The every() method checks if all elements in an array pass a test (provided as a function).
The every() method executes the function once for each element present in the array:
- If it finds an array element where the function returns a false value, every() returns false (and does not check the remaining values)
- If no false occur, every() returns true
Note: every() does not execute the function for array elements without values.
Note: every() does not change the original array
https://www.w3schools.com/jsref/jsref_every.asp
return true if all elements in array passes the check
var a = [4,5,6];
undefined
a.every( (item) => {return item > 4})
false
var a = [5,6];
undefined
a.every( (item) => {return item > 4})
true
No comments:
Post a Comment