JavaScript Array.prototype.every() Method
The every() method checks whether all elements of an array pass a test, returning true or false.
Description
The every() method tests whether all elements pass the test implemented by the callback. It stops as soon as one element fails and returns false; if every element passes, it returns true.
For an empty array it always returns true (there is nothing to fail), which can be surprising when validating input. To check whether at least one element passes, use some().
The callback receives the index and the array as extra arguments, so you can compare each element with its neighbours, for example to check that an array is sorted: arr.every((v, i) => i === 0 || arr[i - 1] <= v). Empty slots in sparse arrays are skipped. It's often used for validation, such as checking that every form field has a value.
Syntax
array.every(callbackFn)
array.every(callbackFn, thisArg)Parameters
- callbackFnA function that tests each element. It should return a truthy value to keep going, and receives
element,indexandarray. - thisArgOptional. A value to use as
thisinsidecallbackFn.
Return Value
true if the callback returns a truthy value for every element, otherwise false. An empty array returns true.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.every() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





