ES6 - Array Method every()


Advertisements

every method tests whether all the elements in an array passes the test implemented by the provided function.

Syntax

array.every(callback[, thisObject]); 

Parameters

  • callback − Function to test for each element.

  • thisObject − Object to use as this when executing callback.

Return Value

Returns true if every element in this array satisfies the provided testing function.

Example

function isBigEnough(element, index, array) { 
   return (element >= 10); 
} 
var passed = [12, 5, 8, 130, 44].every(isBigEnough); 
console.log("Test Value : " + passed );  

Output

Test Value : false
es6_arrays.htm
Advertisements