Array.prototype.every()
Tests whether all elements pass the provided testing function.
Syntax
arr.every(callback, thisArg) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.5 |
| safari | 3.0 |
| edge | 12 |
| node | 0.10 |