TypedArray.prototype.every()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
Theevery() method ofTypedArray instances returnsfalse if it finds one element in the array that does not satisfy the provided testing function. Otherwise, it returnstrue. This method has the same algorithm asArray.prototype.every().
In this article
Try it
function isNegative(element, index, array) { return element < 0;}const int8 = new Int8Array([-10, -20, -30, -40, -50]);console.log(int8.every(isNegative));// Expected output: trueSyntax
every(callbackFn)every(callbackFn, thisArg)Parameters
callbackFnA function to execute for each element in the typed array. It should return atruthy value to indicate the element passes the test, and afalsy value otherwise. The function is called with the following arguments:
thisArgOptionalA value to use as
thiswhen executingcallbackFn. Seeiterative methods.
Return value
true unlesscallbackFn returns afalsy value for a typed array element, in which casefalse is immediately returned.
Description
SeeArray.prototype.every() for more details. This method is not generic and can only be called on typed array instances.
Examples
>Testing size of all typed array elements
The following example tests whether all elements in the typed array are 10 or bigger.
function isBigEnough(element, index, array) { return element >= 10;}new Uint8Array([12, 5, 8, 130, 44]).every(isBigEnough); // falsenew Uint8Array([12, 54, 18, 130, 44]).every(isBigEnough); // trueSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-%typedarray%.prototype.every> |