JavaScript TypedArray findLast() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2023

Definition

typedArray.findLast(callback) works like find(), but it starts at the last element and moves toward the first. It returns the first element it meets that passes the test, which is the last match in normal order. If none passes, it returns undefined. It is useful when the typed array has duplicates or a history of values and you want the newest one. The method is part of ES2023.

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

Uint8Array [70, 90, 55, 62]
  .find(s => s >= 60)      → 70   (first)
  .findLast(s => s >= 60)  → 62   (last)

nothing passes → undefined

Syntax

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

JavaScript
typedArray.findLast(callbackFn)
typedArray.findLast(callbackFn, thisArg)
CallWhat it does
ta.findLast((v) => v < 20)Get the last element below 20.
ta.findLast((v, i, arr) => ...)The callback also gets the index and the typed array. The indexes go down.
ta.findLast(function (v) { ... }, obj)Use obj as this inside a regular function.

ES2023 method on all 11 typed array types. The callback is first called for index length - 1, then length - 2, and so on.

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

// callbackFn(value, index, array), called from the last index down to 0
// returns the element, or undefined if none passed

Parameters

ParameterDescription
callbackFnA function called as (value, index, array). Return a truthy value to pick the element. The index is still the real position, not a count from the end.
thisArgOptional. The value used as this inside callbackFn (not for arrow functions).

Return Value

Return ValueDescription
Number, BigInt, or undefinedThe last element that passed the test, or undefined. See Array findLast() for the regular-array version.

JavaScript Examples

Example 1 — Skip the Error Markers at the End

A sensor writes 255 into a Uint8Array when it fails. To get the latest valid reading we search from the end.

JavaScript
const readings = new Uint8Array([20, 22, 255, 24, 255, 255]);

console.log(readings.findLast((v) => v !== 255));        // 24
console.log(readings.findLast((v) => v === 255));        // 255
console.log('none: ' + readings.findLast((v) => v > 300)); // none: undefined
Try It Yourself

How It Works

  1. The tail is skipped. The last two 255 values fail the test v !== 255, so the search continues until it reaches 24 at index 3.
  2. The very last element can win. For v === 255, the final element already passes and is returned at once.
  3. No match still gives a value. A Uint8Array cannot hold 300, so nothing passes v > 300 and the result is undefined.

Example 2 — First Match Against Last Match

The same test, run in both directions, gives different answers when more than one element passes. Test scores fit in a Uint8Array.

JavaScript
const scores = new Uint8Array([70, 90, 55, 90, 62]);

console.log(scores.find((s) => s >= 60));      // 70
console.log(scores.findLast((s) => s >= 60));  // 62
console.log(scores.find((s) => s < 60));       // 55
console.log(scores.findLast((s) => s < 60));   // 55
Try It Yourself

How It Works

  1. Forward finds 70. find() starts at index 0, and 70 already passes the test, so it is the answer.
  2. Backward finds 62. findLast() starts at index 4, where 62 passes, so the other passing scores are never needed.
  3. A single match gives one answer. Only 55 is below 60, so both methods return it. The directions differ only when duplicates or several matches exist.

Example 3 — See the Indexes Go Down

We record which indexes the callback visits in an Int16Array, and check the empty case.

JavaScript
const temps = new Int16Array([-4, 25, 8, 30, 21]);
const visited = [];

const hit = temps.findLast((v, i) => {
  visited.push(i);
  return v < 20;
});

console.log(hit);                                            // 8
console.log('visited: ' + visited.join(','));                // visited: 4,3,2
console.log('empty: ' + new Int16Array(0).findLast(() => true)); // empty: undefined
Try It Yourself

How It Works

  1. Indexes count down. The callback is called for index 4, then 3, then 2. The index argument is always the true position in the array.
  2. It stops at the first pass. Index 2 holds 8, which is below 20, so indexes 1 and 0 (including -4) are never checked.
  3. Empty means undefined. A typed array of length 0 has nothing to visit, so even a test that always says yes finds nothing.

Browser & Runtime Support

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

✓ Baseline · ES2023

TypedArray.prototype.findLast()

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

Bottom line: Fine for current browsers and servers. For older environments, use find() on a reversed copy or write a short loop from the end.

Frequently Asked Questions

It searches from the end and returns the last element that passes your test. If nothing passes, it returns undefined.
Use it when you want the newest or last match, for example the latest valid reading in a list where older values may match too.
No. It only reads. The typed array stays exactly as it was, and no copy is made.
Chrome 97, Firefox 104, Safari 15.4, Edge 97, and Node.js 18 and newer. It was added in ES2023.
Use findLastIndex(). It returns the position, or -1 if nothing matches.

Next: findLastIndex()

Get the position of the last element that passes a test.

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