JavaScript TypedArray some() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

typedArray.some(callback) checks whether at least one element of a typed array passes a test. It calls your predicate in index order and returns true at the first element where the callback returns a truthy value. If no element passes, it returns false. It does not change the typed array, and on an empty typed array it always returns false.

Remember
typedArray.some(callback, thisArg)   → true or false

callback(value, index, array)
  first element that passes → true (stops there)
  no element passes         → false
  empty typed array         → false

new Int16Array([5, -2]).some((v) => v < 0)   → true

Syntax

Pass a predicate function. The second argument thisArg is optional.

JavaScript
typedArray.some(callback)
typedArray.some(callback, thisArg)
CallWhat it does
ta.some((v) => v < 0)Is there any negative element?
ta.some(Number.isNaN)Is there any NaN in a Float32Array or Float64Array?
ta.some(function (v) { ... }, obj)Set this inside a regular function with the optional thisArg.

Built into JavaScript since ES2015 on all 11 typed array types. The callback receives numbers, or BigInts on BigInt64Array and BigUint64Array.

Library declarations
JavaScript
TypedArray.prototype.some(callbackFn, thisArg?)   // returns a boolean

// callbackFn(value, index, array) -> any value, read as true or false
// empty typed array -> false

Parameters

ParameterDescription
callbackA function called once per element with (value, index, array). Return a truthy value when the element is a match.
thisArgOptional. The value used as this inside the callback. Arrow functions ignore it.

Return Value

Return ValueDescription
Booleantrue if the callback returned a truthy value for at least one element, otherwise false (also for an empty typed array).

JavaScript Examples

Example 1 — Is Any Element a Match?

An Int16Array stores sensor readings. We ask whether any reading is below zero, whether any is above 100, and what an empty typed array says.

JavaScript
const readings = new Int16Array([12, 7, -3, 18]);

console.log(readings.some((v) => v < 0));    // true
console.log(readings.some((v) => v > 100));  // false

const empty = new Int16Array(0);
console.log(empty.some(() => true));         // false
Try It Yourself

How It Works

  1. One negative is enough. The element -3 passes v < 0, so the first question is answered with true.
  2. No reading is above 100. All four readings fail v > 100, so after testing them all the method returns false.
  3. Empty means no match. An empty typed array has no element to match, so even a callback that always returns true is never called and the result is false.

Example 2 — Look for NaN and Stop Early

A Float32Array may hold NaN when a sensor fails. We search for it and count how many elements were tested.

JavaScript
const samples = new Float32Array([1.5, 2.5, NaN, 4.5]);
let calls = 0;

const bad = samples.some((v) => {
  calls++;
  return Number.isNaN(v);
});

console.log(bad);                            // true
console.log('stopped after ' + calls + ' calls');  // stopped after 3 calls
console.log(samples.some(Number.isNaN));     // true
Try It Yourself

How It Works

  1. NaN needs Number.isNaN. A test like v === NaN is never true, so the predicate calls Number.isNaN(v) on each sample instead.
  2. The match ends the search. The third element is NaN, so the counter stops at 3 and the value 4.5 at the end is never looked at.
  3. A ready-made function works too. Number.isNaN can be passed directly as the callback. It ignores the extra index and array arguments.

Example 3 — Neighbours and thisArg

A Uint8Array holds packet bytes. We look for two equal bytes in a row, and for a forbidden byte stored in thisArg.

JavaScript
const bytes = new Uint8Array([7, 7, 9, 3]);

const repeat = bytes.some((v, i, arr) => i > 0 && arr[i - 1] === v);
console.log(repeat);  // true

function isBanned(v) {
  return v === this.code;
}
console.log(bytes.some(isBanned, { code: 9 }));    // true
console.log(bytes.some(isBanned, { code: 200 }));  // false
Try It Yourself

How It Works

  1. Compare each byte with its left neighbour. At index 1 the check arr[i - 1] === v finds 7 next to 7, so some() returns true without testing the rest.
  2. A different this each call. The first call passes { code: 9 } and finds the byte 9 at index 2.
  3. A code that is not stored. With { code: 200 } no byte matches, so every element is tested and the answer is false.

Browser & Runtime Support

TypedArray.prototype.some() is part of ES2015 (ES6), together with the other array-like methods of typed arrays.

✓ Baseline · ES2015

TypedArray.prototype.some()

Supported in every modern browser, plus Node.js, Deno, and Bun.

98% Modern browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 10 and 11 have typed arrays, but not this method
Not supported
some() Excellent

Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer 10 and 11 have typed arrays but not this method, so there you would use a plain for loop.

Frequently Asked Questions

A boolean. It is true as soon as the callback returns a truthy value for one element, and false if no element passes the test.
It always returns false, because there is no element that could pass. The callback is never called. Its partner every() returns true for an empty typed array.
Use ta.some(Number.isNaN). The test v === NaN never works, because NaN is not equal to anything. The includes(NaN) method also finds it on float arrays.
Use includes() when you look for one exact value. Use some() when the test is a rule, such as "any number below zero" or "any byte above 200".
No. It only reads the elements. The typed array keeps its length, its values, and its buffer, whether the answer is true or false.

Next: sort()

Sort a typed array in place, with numbers sorted by value by default.

sort() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful