JavaScript TypedArray findLastIndex() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2023

Definition

typedArray.findLastIndex(callback) searches from the end toward the start and returns the index of the first element it meets that passes your test. In normal order that is the last match. If no element passes, it returns -1. It is the position-based partner of findLast() and was added in ES2023.

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

Int16Array [4, -2, 9, -7, 3]
  .findIndex(v => v < 0)      → 1   (first)
  .findLastIndex(v => v < 0)  → 3   (last)

nothing passes → -1

Syntax

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

JavaScript
typedArray.findLastIndex(callbackFn)
typedArray.findLastIndex(callbackFn, thisArg)
CallWhat it does
ta.findLastIndex((v) => v !== 0)Get the position of the last non-zero element.
ta.findLastIndex((v, i, arr) => ...)The callback also gets the index and the typed array. The indexes go down.
ta.subarray(0, i + 1)A common follow-up: keep everything up to and including the match.

ES2023 method on all 11 typed array types. The callback is called from index length - 1 down to 0, and the result is a plain number.

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

// callbackFn(value, index, array), called from the last index down to 0
// returns the index of the last 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 last element that passed, or -1 if none did. The regular-array twin is Array findLastIndex().

JavaScript Examples

Example 1 — Last Negative Value

An Int16Array holds a few signed readings. We compare the first and the last position of a negative one.

JavaScript
const readings = new Int16Array([4, -2, 9, -7, 3]);

console.log(readings.findIndex((v) => v < 0));      // 1
console.log(readings.findLastIndex((v) => v < 0));  // 3

const last = readings.findLastIndex((v) => v < 0);
console.log('value there: ' + readings[last]);      // value there: -7
Try It Yourself

How It Works

  1. Front to back gives 1. findIndex() meets -2 first, at index 1, and stops.
  2. Back to front gives 3. findLastIndex() checks 3 and 9 and rejects them, then meets -7 at index 3.
  3. The index reads the value. Using the result as readings[last] returns -7, the stored number at that position.

Example 2 — When Nothing Matches

If no element passes, the answer is -1. An empty typed array also gives -1, because there is nothing to test.

JavaScript
const ids = new Uint8Array([3, 8, 3]);

const none = ids.findLastIndex((id) => id === 5);
console.log(none);                                          // -1
console.log('ids[-1] is ' + ids[none]);                     // ids[-1] is undefined
console.log(new Uint8Array(0).findLastIndex(() => true));   // -1
console.log(ids.findLastIndex((id) => id === 3));           // 2
Try It Yourself

How It Works

  1. Three tests, no yes. The callback rejects 3, 8, and 3 in turn (from the end), so the search finishes with -1.
  2. Minus one is not a real index. Reading ids[none] quietly gives undefined, so always check the result first.
  3. Duplicates give the later one. The value 3 appears at index 0 and index 2. The search from the end meets index 2 first.

Example 3 — Cut Off Padding at the End

A network packet in a Uint8Array is padded with zero bytes. We find the last real byte and keep everything before the padding.

JavaScript
const packet = new Uint8Array([7, 0, 9, 0, 0]);

const end = packet.findLastIndex((b) => b !== 0);
const trimmed = packet.subarray(0, end + 1);

console.log('end: ' + end);                            // end: 2
console.log(trimmed.join(' '));                        // 7 0 9
console.log(trimmed.length);                           // 3
console.log(trimmed.buffer === packet.buffer);         // true
Try It Yourself

How It Works

  1. The padding is skipped. From the end, the last two zeros fail b !== 0, and 9 at index 2 is the last real byte.
  2. End plus one is the length. The subarray(0, end + 1) call takes indexes 0, 1, and 2. The zero between 7 and 9 is kept because it is not trailing.
  3. No bytes are copied. subarray() returns a view on the same ArrayBuffer, so trimmed.buffer === packet.buffer is true.

Browser & Runtime Support

TypedArray.prototype.findLastIndex() is part of ES2023, so it needs a recent browser or runtime.

✓ Baseline · ES2023

TypedArray.prototype.findLastIndex()

Chrome 97, Firefox 104, Safari 15.4, Edge 97, and Node.js 18 added it.

93% Recent browsers only
Google Chrome Chrome 97 and newer
Full support
Mozilla Firefox Firefox 104 and newer
Full support
Apple Safari Safari 15.4 and newer
Full support
Microsoft Edge Edge 97 and newer
Full support
Node.js Node.js 18 and newer
Supported
Deno Recent versions
Supported
Internet Explorer No support
Not supported
findLastIndex() Recent browsers

Bottom line: Fine for current browsers and servers. For older environments, loop from length - 1 down to 0 yourself.

Frequently Asked Questions

The index of the last element that passes your test, found by searching from the end. It returns -1 if no element passes.
findLast() returns the element value and findLastIndex() returns its position. Both search from the end.
No. It is the normal index counted from the start. In [4, -2, 9, -7, 3], the last negative number is at index 3.
Yes. There is nothing to test, so the callback is never called and the result is -1.
lastIndexOf() looks for an exact value with strict equality. findLastIndex() runs your own test, so it can use ranges, conditions, and the index.

Next: forEach()

Run a function once for every element of the typed array.

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