JavaScript Array findLastIndex() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
ES2023

What You’ll Learn

The findLastIndex() method returns the index of the last element that passes your test, searching from the end. If nothing matches, it returns -1. This ES2023 tutorial covers syntax, five examples, comparisons with findIndex() and findLast(), and practical update/remove patterns.

01

Syntax

findLastIndex(cb)

02

Last index

Tail-first

03

No match

-1

04

vs findIndex

End vs start

05

Splice ready

Update/remove

06

ES2023

Modern JS

Introduction

findLast() tells you what matched at the tail. findLastIndex() tells you where it matched—so you can remove it, replace it, or scroll a list to that row.

It is the tail-first partner of findIndex(), added in ES2023 alongside findLast().

Understanding the findLastIndex() Method

array.findLastIndex(callback) invokes your callback starting at the last index and moving toward 0. The first truthy result returns that index immediately.

If every callback is falsy, the result is -1.

💡
Beginner Tip

Compare with index !== -1, not truthiness—index 0 is valid but falsy in an if (index) check.

📝 Syntax

General form of Array.prototype.findLastIndex:

JavaScript
array.findLastIndex(callback(element, index, array), thisArg)

Parameters

  • callback — predicate tested on each element from end to start.
  • element — current array item.
  • index — optional; position of the element.
  • array — optional; the array being searched.
  • thisArg — optional; value to use as this inside the callback.

Return value

  • Index of the last matching element (0-based).
  • -1 if no element passes the test.
  • Original array unchanged by the search itself.

Common patterns

  • arr.findLastIndex(n => n % 2 === 0) — last even index.
  • arr.findLastIndex(x => x.id === id) — last object with id.
  • if (i !== -1) arr.splice(i, 1) — remove last match.

⚡ Quick Reference

GoalCode
Last match indexarr.findLastIndex(callback)
Search directionEnd → start
No match-1
Need value insteadfindLast()
StandardES2023

📋 findLastIndex() vs findIndex() vs findLast() vs lastIndexOf

Tail vs head search, custom predicate vs strict equality, index vs value.

findLastIndex
last index

Tail-first, -1 fail

findIndex
first index

Head-first

findLast
last value

undefined fail

lastIndexOf
=== value

Primitives only

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Find the index of the last passing element.

Example 1 — Index of the Last Even Number

In [1, 2, 3, 4, 5, 2], the last even value is at index 5.

JavaScript
const numbers = [1, 2, 3, 4, 5, 2];

const lastIndex = numbers.findLastIndex((n) => n % 2 === 0);

console.log(lastIndex);
// 5
Try It Yourself

How It Works

Indexes 5, 3, and 1 are even. Tail-first search hits index 5 first and returns it.

Example 2 — Handle -1 When Nothing Matches

Guard before using the index in splice or assignment.

JavaScript
const numbers = [1, 2, 3, 4, 5, 2];

const lastIndex = numbers.findLastIndex((n) => n > 10);

if (lastIndex === -1) {
  console.log("No element greater than 10 found.");
} else {
  console.log("Index:", lastIndex);
}
// No element greater than 10 found.
Try It Yourself

How It Works

-1 means failure, matching findIndex and indexOf conventions.

📈 Practical Patterns

Compare directions, find duplicates, mutate by index.

Example 3 — findIndex() vs findLastIndex()

Same predicate, different scan direction, different index on duplicates.

JavaScript
const numbers = [1, 2, 3, 4, 5, 2];

const firstTwo = numbers.findIndex((n) => n === 2);
const lastTwo = numbers.findLastIndex((n) => n === 2);

console.log(firstTwo);
// 1
console.log(lastTwo);
// 5
Try It Yourself

How It Works

2 appears at indexes 1 and 5. Head-first finds 1; tail-first finds 5. For strict equality on primitives, lastIndexOf(2) also returns 5.

Example 4 — Last Occurrence of a Value

Locate the final duplicate of a target number.

JavaScript
const numbers = [1, 2, 3, 4, 5, 2];
const target = 2;

const lastOccurrence = numbers.findLastIndex((n) => n === target);

console.log(lastOccurrence);
// 5
Try It Yourself

How It Works

For simple value search, lastIndexOf(target) is equivalent. Use findLastIndex when the condition is more than ===.

Example 5 — Remove the Last Matching Item

Find the tail index, then splice one element.

JavaScript
const tags = ["js", "html", "css", "js", "node"];

const i = tags.findLastIndex((t) => t === "js");

if (i !== -1) {
  tags.splice(i, 1);
}

console.log(tags);
// ["js", "html", "css", "node"]
Try It Yourself

How It Works

Only the last "js" at index 3 is removed; the first "js" at index 0 remains.

🚀 Common Use Cases

  • Remove last duplicate — splice the final matching tag or category.
  • Update trailing record — replace the most recent matching row.
  • Deduplication — keep first occurrence via findLastIndex in filters.
  • Log analysis — index of the latest error for detail panels.
  • Form arrays — focus the last invalid field in a list.
  • Undo stacks — find the last reversible action marker.

🧠 How findLastIndex() Runs

1

Start at length - 1

Evaluate from the last index backward.

Tail
2

Run callback

Pass (element, index, array) each step.

Test
3

Truthy?

Return that index and stop.

Match
4

Index 0 checked

If nothing passed, return -1.

📝 Notes

  • ES2023—pair with feature detection or polyfills for old browsers.
  • Returns -1 on failure, not undefined.
  • Index 0 is valid; use index !== -1 for found checks.
  • For primitive equality only, lastIndexOf may suffice.
  • Short-circuits at the first match from the tail.
  • Works on typed arrays with the same signature.

Browser & Runtime Support

Array.prototype.findLastIndex() was added in ES2023 together with findLast(). It is available in current evergreen browsers and Node.js 18+.

Baseline · ES2023

Array.prototype.findLastIndex()

Supported in Chrome 97+, Firefox 104+, Safari 15.4+, Edge 97+, and Node 18+. Not available in Internet Explorer or very old mobile browsers.

92% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.findLastIndex() Very Good

Bottom line: Safe for modern apps on current browser versions. Polyfill or backward for-loop when older clients must be supported.

Conclusion

The findLastIndex() method closes the tail-search loop: you get a numeric slot for the last match, ready for splice, assignment, or UI focus—without reversing the array.

Combine it with findLast() when you need the value, and with findIndex() when the first match is what matters.

💡 Best Practices

✅ Do

  • Check index !== -1 before splice or assign
  • Use for last-duplicate removal and tail updates
  • Return explicit booleans from callbacks
  • Feature-detect in mixed browser targets
  • Prefer lastIndexOf for simple primitive search

❌ Don’t

  • Use if (index) as a found check
  • Expect the element—use findLast() for values
  • Assume IE or old Safari support without polyfill
  • Mutate array order during the search callback
  • Use when you need every match (filter)

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.findLastIndex()

Your foundation for tail-first index searches in ES2023.

5
Core concepts
🔃 02

Tail-first

End → start.

Direction
🔢 03

Returns index

Number.

Position
04

No match

-1

Sentinel
📅 05

ES2023

With findLast.

Standard

❓ Frequently Asked Questions

findLastIndex() returns the index of the last element for which the callback returns a truthy value. It searches from the end of the array toward the start. If no element matches, it returns -1.
No. findLastIndex() only reads elements through your callback. The original array is unchanged unless you mutate it afterward using the returned index.
It returns -1, the same sentinel used by findIndex, indexOf, and lastIndexOf when a search fails.
findLastIndex() returns the numeric index (or -1). findLast() returns the matching element itself (or undefined). Use findLastIndex when you need to splice, assign, or focus a UI row by position.
findIndex() scans from the start and returns the first match index. findLastIndex() scans from the end and returns the last match index.
findLastIndex() is an ES2023 feature. It works in Chrome 97+, Firefox 104+, Safari 15.4+, Edge 97+, and Node 18+. Older environments need a polyfill or a backward loop.
Did you know?

Before ES2023, getting the last matching index often meant arr.map((v,i)=>i).reverse().find(...) or a manual backward loop. findLastIndex() does the same in one readable call.

Continue to flat()

Learn how to flatten nested arrays one level (or more) into a simpler structure.

flat() 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.

6 people found this page helpful