The every() method of TypedArray instances returns false if it finds an element in the array that does not satisfy the provided testing function. Otherwise, it returns true. This method has the same algorithm as Array.prototype.every().
function isNegative(element, index, array) {
return element < 0;
}
const int8 = new Int8Array([-10, -20, -30, -40, -50]);
console.log(int8.every(isNegative));
// Expected output: trueevery(callbackFn)
every(callbackFn, thisArg)callbackFnA function to execute for each element in the typed array. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. The function is called with the following arguments:
elementThe current element being processed in the typed array.
indexThe index of the current element being processed in the typed array.
arrayThe typed array every() was called upon.
thisArg OptionalA value to use as this when executing callbackFn. See iterative methods.
true unless callbackFn returns a falsy value for a typed array element, in which case false is immediately returned.
See Array.prototype.every() for more details. This method is not generic and can only be called on typed array instances.
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); // false
new Uint8Array([12, 54, 18, 130, 44]).every(isBigEnough); // true