JavaScript TypedArray findIndex() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

typedArray.findIndex(callback) checks the elements from the first to the last and returns the index of the first one for which your callback returns a truthy value. If none passes, it returns -1. Use it when you need the position of an element, for example to overwrite it afterwards. It never changes the typed array by itself.

Remember
typedArray.findIndex((value, index, array) => test)

new Uint8Array([18, 22, 31]).findIndex(t => t > 20)  โ†’ 1
new Uint8Array([18, 22, 31]).findIndex(t => t > 99)  โ†’ -1

first match wins ยท returns the POSITION (or -1)

Syntax

findIndex() takes a callback and an optional thisArg. Call it on any typed array.

JavaScript
typedArray.findIndex(callbackFn)
typedArray.findIndex(callbackFn, thisArg)
CallWhat it does
ta.findIndex((v) => v > 30)Get the position of the first element greater than 30.
ta.findIndex((v, i, arr) => ...)The callback also gets the index and the typed array itself.
ta.findIndex((v) => v === 0)Look for a value by equality. For plain values, indexOf() is shorter.

Built into JavaScript since ES2015 on all 11 typed array types. The index is always a plain number, even on BigInt typed arrays.

Library declarations
JavaScript
TypedArray.prototype.findIndex(callbackFn, thisArg)

// callbackFn(value, index, array) -> truthy: stop here
// returns the index of the first passing element, or -1

Parameters

ParameterDescription
callbackFnA function called as (value, index, array). Return a truthy value for the element you want.
thisArgOptional. The value used as this inside callbackFn (not for arrow functions).

Return Value

Return ValueDescription
NumberThe index of the first element that passed, or -1 if none did. It is the position-based twin of Array findIndex().

JavaScript Examples

Example 1 — Where Is the First Hot Reading?

Five temperatures sit in a Uint8Array. findIndex() reports where the first matching one lives.

JavaScript
const temps = new Uint8Array([18, 22, 31, 27, 35]);

console.log(temps.findIndex((t) => t > 30));                    // 2
console.log(temps.findIndex((t, i, arr) => i > 0 && t < arr[i - 1])); // 3
console.log(temps.findIndex((t) => t === 18));                  // 0
Try It Yourself

How It Works

  1. Position, not value. The first reading above 30 is 31, and it sits at index 2, so that is what findIndex() returns, not 31.
  2. Compare with the neighbour. The callback reads arr[i - 1] to find the first drop: 27 is lower than 31, and 27 is at index 3.
  3. Zero is a real answer. The reading 18 is the first element, so the result is 0. Only -1 would mean "not found".

Example 2 — Handle the -1 Result

Product ids live in a Uint16Array. When the id is missing, findIndex() answers -1, and reading with that index is a quiet bug.

JavaScript
const ids = new Uint16Array([300, 450, 120]);

const pos = ids.findIndex((id) => id === 999);
console.log(pos);                                  // -1
console.log('ids[-1] is ' + ids[pos]);             // ids[-1] is undefined
console.log(pos === -1 ? 'not found' : 'found');   // not found
console.log(ids.findIndex((id) => id === 300));    // 0
Try It Yourself

How It Works

  1. No id equals 999. The callback says no three times, so the loop ends without a match and -1 comes back.
  2. Reading at -1 is silent. ids[-1] does not throw: it just yields undefined, which can hide a bug if you forget the check.
  3. A guard keeps it safe. Comparing pos === -1 separates "missing" from the valid index 0 that the last line shows for id 300.

Example 3 — Fill the First Free Slot

An Int32Array holds order numbers, and 0 marks an empty slot. We find a slot and write into it.

JavaScript
const slots = new Int32Array([501, 502, 0, 504, 0]);

const free = slots.findIndex((id) => id === 0);
slots[free] = 777;

console.log('free slot: ' + free);                  // free slot: 2
console.log(slots.join(' '));                       // 501 502 777 504 0
console.log('next free: ' + slots.findIndex((id) => id === 0)); // next free: 4
Try It Yourself

How It Works

  1. The first zero is at 2. Index 4 also holds 0, but findIndex() stops at index 2 and never looks further.
  2. The index becomes a write target. slots[free] = 777 stores the new order in place. An Int32Array changes in place and its length stays 5.
  3. Searching again moves on. Index 2 now holds 777, so a second search skips it and lands on the remaining empty slot at index 4.

Browser & Runtime Support

TypedArray.prototype.findIndex() arrived with typed arrays and Array.prototype.findIndex() in ES2015 (ES6).

✓ Baseline · ES2015

TypedArray.prototype.findIndex()

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
findIndex() Excellent

Bottom line: Safe everywhere modern JavaScript runs. Only Internet Explorer is missing it: IE 10 and 11 have typed arrays, but not this method.

Frequently Asked Questions

It returns -1. Check for -1 before you use the result as an index.
Use indexOf() when you know the exact value. Use findIndex() when you need a test, such as "first value above 30".
Yes. It stops at the first index where the callback is truthy. For the last match, use findLastIndex().
Yes. The callback receives BigInt values, so compare with BigInt literals like 5n. The returned index is still a normal number.
Index 0 is falsy in JavaScript, so if (i) skips it. Always write i !== -1 to test whether a match exists.

Next: findLast()

Search from the end of the typed array and return the last element that passes a test.

findLast() 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