every() function in JavaScript

Executes a function for each array element. Returns true if the function returns true for all elements. Returns false if the function returns false for one element.

Sample code

let array = [10,2,4,6,8];
console.log(array.every(obj => obj%2 === 0))

Here log will be true because every element in the array satisfies the condition. If the value of array is [11,2,4,6,8], the output will be zero because there is an element 11 that does not satisfy the condition.

Leave a comment

Your email address will not be published. Required fields are marked *