Created
May 1, 2014 18:10
-
-
Save mojaray2k/11457872 to your computer and use it in GitHub Desktop.
In ES5 there were added a number of new Array methods, including Array.prototype.every(). With this method you can check all the items inside an array for a condition that's defined in a callback function. The method will return true if all items meet the conditions, but will return false as soon as it finds one item in the array that doesn't me…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var set1 = [2, 4, 6, 8, 10]; | |
var set2 = [2, 4, 5, 8, 10]; | |
console.log(set1.every(function (a) { | |
return a % 2 === 0; | |
})); // true | |
console.log(set2.every(function (a) { | |
return a % 2 === 0; | |
})); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment