Lodash _.findLastIndex() method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.findLastIndex(collection, predicate, [fromIndex]) returns the last matching index in reverse scan order, or -1.
  • When to prefer it over _.findIndex() for duplicates, logs, or timeline data.
  • How it lines up with native findLastIndex (ES2023) and Lodash iteratee shorthand.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.findIndex() on this site first; both APIs share the same predicate and iteratee rules.

  • You understand that “last” refers to the greatest index that matches when scanning from the end of the array.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.findLastIndex is the right-to-left twin of _.findIndex: it finds the last element satisfying your predicate. That is the tool you want for “most recent” rows, trailing flags, or the final duplicate in a list before you splice or split.

Reverse scan

Evaluation starts near the end of the array and moves toward index 0, so later duplicates win.

Non-destructive

The collection is not mutated; you only receive an index or -1.

Same iteratees

Functions, property paths, and partial objects work just like on findIndex.

Syntax

javascript
_.findLastIndex(collection, [predicate=_.identity], [fromIndex=collection.length - 1])
  • collection: array or array-like value scanned from a starting index toward 0.
  • predicate: invoked as (value, index, collection); the first truthy result encountered during the reverse walk wins. Lodash iteratee shorthand applies.
  • fromIndex: where the reverse scan begins (defaults to the last index).
  • Returns: the index of the matched element, or -1 if none.
1

Last index with a custom test

When the same value appears more than once, findLastIndex returns the rightmost match.

javascript
import findLastIndex from "lodash/findLastIndex";

findLastIndex([1, 2, 3, 2, 4], (x) => x === 2);
// 3
Try it Yourself
2

Partial object iteratee

With duplicate records, the partial object form still resolves to the last row that matches.

javascript
import findLastIndex from "lodash/findLastIndex";

const rows = [{ id: 1 }, { id: 2 }, { id: 2 }];

findLastIndex(rows, { id: 2 });
// 2
Try it Yourself
3

Bound the reverse search

fromIndex sets where the reverse walk starts. Here the last 2 in the full array would be index 3, but starting at 2 stops the search before that slot.

javascript
import findLastIndex from "lodash/findLastIndex";

findLastIndex([1, 2, 3, 2], (x) => x === 2, 2);
// 1
Try it Yourself

📋 _.findLastIndex vs _.findIndex vs native

APIScan directionNote
_.findLastIndexEnd toward startLast match; iteratee shorthand; fromIndex caps where the reverse pass begins
_.findIndexStart toward endFirst match; same shorthands
Array.prototype.findLastIndexEnd toward startNative ES2023; callback only (no Lodash partial-object iteratee)

Pitfalls to avoid

Order

Not the largest index in the whole array

It is the last match in the reverse scan from fromIndex. A smaller fromIndex can skip matches that sit to the right.

NaN

Same as findIndex

NaN never satisfies ===; use Number.isNaN or _.isNaN inside the predicate when hunting for NaN slots.

-1

Guard splice and slice

Treat -1 like “not found” before passing the index into APIs that interpret negative numbers specially.

❓ FAQ

No. It only reads the collection and returns a number (the index) or -1 when nothing matches.
It returns -1, same as _.findIndex when there is no match.
findIndex scans from the start toward the end and returns the first match. findLastIndex scans from the end (or from a resolved fromIndex) toward the start and returns the last match in that scan order.
It is the index where the reverse scan begins (clamped to the array bounds). Lodash then walks toward index 0 looking for a truthy predicate result.
Use import findLastIndex from "lodash/findLastIndex" or require("lodash/findLastIndex") for tree-shaking friendly bundles.

Summary

  • Purpose: _.findLastIndex(collection, predicate, fromIndex) returns the index of the last element matching the predicate in reverse scan order, or -1.
  • Safety: the input collection is not mutated by this call.
  • Next: Lodash _.flatten(), _.findIndex() (earlier in this track), or the array methods hub.
Did you know?

ES2023 added native Array.prototype.findLastIndex; Lodash’s version still helps when you want the same iteratee shorthands and consistent behavior across older runtimes.

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