The Array.every() method in JavaScript is used to checks whether all the elements of the array satisfy the given condition or not.
The Array.some() method in JavaScript is used to check whether at least one of the elements of the array satisfies the given condition or not.
The only difference is that the some() method will return true if any predicate is true while every() method will return true if all predicate are true.
Example 1: This example implements the some() method.
<script> // JavaScript code for some() function function isodd(element, index, array) { return (element % 2 == 1); } function geeks() { var arr = [ 6, 1, 8, 32, 35 ]; // check for odd number var value = arr.some(isodd); console.log(value); } geeks(); </script> |
Output:
true
Example 2: This example implements the every() method.
<script> // JavaScript code for every() function function isodd(element, index, array) { return (element % 2 == 1); } function geeks() { var arr = [ 6, 1, 8, 32, 35 ]; // check for odd number var value = arr.every(isodd); console.log(value); } geeks(); </script> |
Output:
false
Recommended Posts:
- Some newly introduced array methods in JavaScript ES6
- What is the difference between find() and filter() methods in JavaScript ?
- What is the difference between Object.keys() and Object.entries() methods in JavaScript ?
- JavaScript Array some() Method
- JavaScript | typedArray.some() with Example
- Difference between process.nextTick() and setImmediate() Methods
- Underscore.js | some() with Examples
- How to check a selector matches some content using jQuery?
- How to check a string begins with some given characters/pattern ?
- How to call a function automatically after waiting for some time using jQuery?
- How to select all elements that contains some specific CSS property using jQuery ?
- TypeScript | Array some() Method
- How to validate if input in input field exactly equals to some other value using express-validator ?
- Lodash _.some() Method
- JavaScript Basic Array Methods
- JavaScript | Set Date Methods
- JavaScript | Get Date Methods
- JavaScript | Object Methods
- JavaScript | Array Iteration Methods
- JavaScript methods to increment/decrement alphabetical letters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


