Array.prototype.every()

Tests whether all elements pass the provided testing function.

Since ES5 Spec ↗

Syntax

arr.every(callback, thisArg)

Parameters

NameTypeRequiredDescription
callback Function Yes Predicate called with (element, index, array). Return truthy if the element passes.
thisArg any No Value to use as `this` when executing the callback.

Returns

boolean — true if the callback returns truthy for every element; otherwise false.

Examples

console.log([2, 4, 6].every(n => n % 2 === 0));
Output
true
console.log([].every(n => n > 0));
Output
true

Notes

Short-circuits and returns false on the first failing element. Returns true for an empty array (vacuous truth). Use `some` to require just one match.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.5
safari 3.0
edge 12
node 0.10

See also