Underscore.js _.findLastIndex() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Like _.findIndex, but iterates the array in reverse and returns the index closest to the end where the predicate truth test passes (official Underscore docs).

Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.findLastIndex. Start with this line.

Underscore
_.findLastIndex(array, predicate, [context])
CallWhat it does
_.findLastIndex(array, predicate, [context])Primary signature.
_.findLastIndex(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.findLastIndex(array, predicate, [context])

Parameters

ParameterDescription
arrayRequired. List to search (backward)
predicateRequired. Function or iteratee (matcher / property)
contextOptional. this for a function predicate

Return Value

Return ValueDescription
*Index number, or -1

Underscore.js Examples

Example 1 — Official Matcher Object

Pass a property matcher — Underscore finds the last object that matches.

Underscore
var users = [
  { id: 1, name: "Bob", last: "Brown" },
  { id: 2, name: "Ted", last: "White" },
  { id: 3, name: "Frank", last: "James" },
  { id: 4, name: "Ted", last: "Jones" }
];

_.findLastIndex(users, { name: "Ted" });
// → 3
Try It Yourself

How It Works

  1. Four users. Indexes 0 … 3; two are named Ted.
  2. Matcher. { name: "Ted" } becomes an iteratee via Underscore.
  3. Reverse scan. Index 3 matches first from the end.
  4. Result. Returns 3 (Ted Jones), not 1 (Ted White).

Example 2 — Predicate Function

Use a function when the rule is more than a fixed property match.

Underscore
var numbers = [4, 7, 8, 9, 10];

_.findLastIndex(numbers, function (n) {
  return n % 2 !== 0;
});
// → 3  (value 9)
Try It Yourself

How It Works

  1. Rule. Keep numbers that are odd (n % 2 !== 0).
  2. From the end. Check 10 (even), then 9 (odd).
  3. Stop. Index 3 passes — return immediately.
  4. Earlier odds. Index 1 (7) is never needed once the last hit is found.

Example 3 — No Match Returns -1

When every element fails the test, you get -1 — same idea as indexOf.

Underscore
var ages = [12, 15, 17];

_.findLastIndex(ages, function (age) {
  return age >= 18;
});
// → -1
Try It Yourself

How It Works

  1. Rule. Look for age ≥ 18.
  2. All fail. 17, 15, and 12 are under 18.
  3. Signal. Underscore returns -1 (not found).
  4. Safe use. Always check index !== -1 before reading ages[index].

Example 4 — _.findIndex vs _.findLastIndex

Same predicate, opposite ends — first match vs last match.

Underscore
var nums = [10, 3, 20, 5, 30];
var isBig = function (n) { return n >= 20; };

_.findIndex(nums, isBig);      // → 2  (value 20)
_.findLastIndex(nums, isBig);  // → 4  (value 30)
Try It Yourself

How It Works

  1. Shared rule. Both look for values ≥ 20.
  2. From the start. _.findIndex hits 20 at index 2.
  3. From the end. _.findLastIndex hits 30 at index 4.
  4. Pick by intent. Need the earliest hit → findIndex; the latest → findLastIndex.

Browser & Runtime Support

_.findLastIndex ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore. Native Array.prototype.findLastIndex is separate (ES2023) and is not required.

✓ Stable · Underscore 1.x

_.findLastIndex()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
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
_.findLastIndex Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.findLastIndex(array, predicate, [context]) returns the index of the last element that passes a truth test, searching from the end. If nothing matches, it returns -1.
_.findIndex scans from the start and returns the first passing index. _.findLastIndex scans from the end and returns the last passing index. Both share the same predicate / iteratee rules.
Yes. Underscore runs the predicate through _.iteratee, so a matcher like { name: 'Ted' } works — that is the official docs example.
_.lastIndexOf looks for a value with strict === equality. _.findLastIndex runs a predicate (or matcher) so you can match by property, range, or any custom rule.
It returns -1. Check with if (index !== -1) before using the index to update or splice.
No. It only reads the array and returns a number. The source stays unchanged.

Next: _.range()

Generate flexible integer lists — handy for each and map loops.

_.range() 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.

10 people found this page helpful