The every() method in JavaScript is used to check whether all elements in an array satisfy a particular condition. It returns a boolean value – true if all elements meet the specified condition, and false otherwise.
Example: Here, the every() method is used to check if every element in the numbers array is even. Since all elements in this case are even, the every() method returns true .
Javascript
let numbers = [2, 4, 6, 8, 10];
let allEven = numbers.every( function (num) {
return num % 2 === 0;
});
console.log(allEven);
|
|