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(); |
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.