Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Created May 1, 2014 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojaray2k/11457872 to your computer and use it in GitHub Desktop.
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…
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