Skip to content
Related Articles

Related Articles

What is the difference between every() and some() methods in JavaScript ?
  • Last Updated : 15 Apr, 2020

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :