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

The some() method of TypedArray instances tests whether at least one element in the typed array passes the test implemented by the provided function. It returns true if, in the typed array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the typed array. This method has the same algorithm as Array.prototype.some.

Syntax

some(callbackFn)
some(callbackFn, thisArg)

Parameters

Return value

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

Description

See Array.prototype.some 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 any element in the typed array is bigger than 10.

function isBiggerThan10(element, index, array) {
  return element > 10;
}
new Uint8Array([2, 5, 8, 1, 4]).some(isBiggerThan10); // false
new Uint8Array([12, 5, 8, 1, 4]).some(isBiggerThan10); // true

Specifications

Browser compatibility

See also