UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ TypedArray/ TypedArray.prototype.every()

The every() method of TypedArray instances tests whether all elements in the typed array pass the test implemented by the provided function. It returns a Boolean value. This method has the same algorithm as Array.prototype.every.

Syntax

every(callbackFn)
every(callbackFn, thisArg)

Parameters

Return value

true unless callbackFn returns a value for a typed array element, in which case false is immediately returned.

Description

See Array.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 bigger than 9.

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

Specifications

Browser compatibility

See also