Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 04 Apr, 2022

The Array.every() method in JavaScript is used to check 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 predicates are true. 

Example 1: This example implements the some() method. 

javascript




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

javascript




<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

Let us see the Differences in Tabular Form -:

 Array.every()Array.some()
1.The Array.every() method is used to check whether all the elements of the array satisfy the given condition or not.The Array.some() method is used to check whether at least one of the elements of the array satisfies the given condition or not.
2.The  some() method will return true if any predicate is trueThe every() method will return true if all predicates is true
3.This method executes a function for each array element.This method does not execute the function for empty array elements.
4.This method does not execute the function for empty elements.This method does not change the original array.
5.This method does not change the original arrayIts return value is of Boolean type
6.

Its Syntax is -: 

array.every(function(value, index, array), thisValue)

Its syntax is -:

array.some(function(value, index, array), this)

7.

Its supported browsers are -:

Chrome, Internet Explorer 9 – 11, Firefox, Safari, Microsoft Edge, Opera

Its supported browsers are -:

Chrome, Internet Explorer, Firefox, Safari, Microsoft Edge, Opera


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!