every()

ES5+

Tests whether all elements in the array pass the test implemented by the provided function.

Syntax

array.every(callback(element, index, array), thisArg)

Parameters

callback Function

Function to test each element

Return Value

boolean

true if all elements pass the test

Examples

JavaScript
const numbers = [2, 4, 6, 8];
const allEven = numbers.every(x => x % 2 === 0);
console.log(allEven);
Output:
// true

Related Methods