Array.every() method

The Array.every() method in JavaScript is used to check whether all the elements of the array satisfy the given condition or not. The output will be false if even one value does not satisfy the element, else it will return true, and it opposes the some() function.

Syntax:

// Arrow function
every((element) => { /* … */ })
every((element, index) => { /* … */ })
every((element, index, array) => { /* … */ })

Example: This example implements the every() method. 

javascript




// JavaScript code for every() function
function isodd(element, index, array) {
    return (element % 2 == 1);
}
 
function geeks() {
    let arr = [6, 1, 8, 32, 35];
 
    // check for odd number
    let value = arr.every(isodd);
    console.log(value);
}
geeks();


Output

false

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

In this article, we will see the difference between every() and some() methods in JavaScript.

Similar Reads

Array.every() method

The Array.every() method in JavaScript is used to check whether all the elements of the array satisfy the given condition or not. The output will be false if even one value does not satisfy the element, else it will return true, and it opposes the some() function....

Array.some() method

...

Differences between Array.every() and Array.some()

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. and it accepts true/false boolean expressions, 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....