Array

Array.prototype.every

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

Syntax

JavaScript
array.every(callbackFn, thisArg?)

Parameters

ParameterTypeDescription
callbackFn(element, index, array) => booleanFunction to test each element
thisArganyValue to use as this when executing callbackFn

Return Value

true if all elements pass the test, false otherwise

Examples

Basic Usage
const numbers = [2, 4, 6, 8];
const allEven = numbers.every(n => n % 2 === 0);
console.log(allEven); // true
Practical Example
const ages = [18, 21, 25, 30];
const allAdults = ages.every(age => age >= 18);
console.log(allAdults); // true
Advanced Usage
const values = [1, 2, 3, -1];
console.log(values.every(v => v > 0)); // false

Understanding Array.prototype.every

The Array.prototype.every method in JavaScript tests whether all elements in the array pass the test implemented by the provided function. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.every(callbackFn, thisArg?). It accepts 2 parameters: callbackFn, thisArg. When called, it returns true if all elements pass the test, false otherwise. Understanding when and how to use every() helps you write more expressive, readable code.

Common use cases for Array.prototype.every include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-some, array-filter, array-find, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.every is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.