What is the difference between every() and some() methods in JavaScript ?

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:



true

Example 2: This example implements the every() method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:

false

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.