Lodash _.findIndex() method

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

What you’ll learn

  • How _.findIndex(collection, predicate, [fromIndex=0]) returns the first matching index or -1.
  • Using callbacks, partial-object iteratees, and an optional fromIndex search start.
  • How this compares to native Array.prototype.findIndex and to _.find (value vs index).
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Optional prior read _.fill() on this site; you should be comfortable with array indexes and truthy versus falsy values.

  • You can read a predicate as (value, index, collection) => boolean without mutating arguments.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.findIndex answers “where is the first match?” by returning a numeric index. It pairs naturally with slice, splice, or immutable updates that need a position. Unlike _.find, you get an index (or -1), not the element itself.

Non-destructive

The source collection is read-only for this call; only the returned number reflects the outcome.

Predicate-first

Express arbitrary tests; use iteratee shorthand when you only need property or partial-object matching.

fromIndex

Skip early matches when you need the next occurrence after a known position.

Syntax

javascript
_.findIndex(collection, [predicate=_.identity], [fromIndex=0])
  • collection: array or array-like value scanned from low indexes upward.
  • predicate: invoked as (value, index, collection); the first truthy result selects that index. Lodash also accepts iteratee shorthand (string path, partial object, and so on).
  • fromIndex: where to begin searching (defaults to 0).
  • Returns: the zero-based index of the first match, or -1 if none.
1

First index with a custom test

The predicate runs left to right; the first element for which it is truthy determines the returned index.

javascript
import findIndex from "lodash/findIndex";

findIndex([10, 20, 30, 40], (x) => x > 25);
// 2
Try it Yourself
2

Partial object iteratee

Pass an object to match elements that contain the same own properties (Lodash “matches” shorthand).

javascript
import findIndex from "lodash/findIndex";

const rows = [
  { id: 1, role: "guest" },
  { id: 2, role: "admin" }
];

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

Start the search later

With fromIndex, skip earlier matches; here the first 2 is at index 0, but the search begins at 1.

javascript
import findIndex from "lodash/findIndex";

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

📋 _.findIndex vs native findIndex

APIWhy LodashNote
_.findIndex(collection, predicate, fromIndex)Iteratee shorthand, consistent fromIndex behavior, works with array-like values in one stylePrefer when the rest of your module already imports Lodash helpers
Array.prototype.findIndexBuilt-in, zero dependencyGreat on real arrays when you only need a callback (no partial-object iteratee)
_.findReturns the matched value (or undefined)Use findIndex when you specifically need the index

Pitfalls to avoid

NaN

Strict equality surprises

x === NaN is always false. Use Number.isNaN inside the predicate, or rely on Lodash helpers such as _.isNaN where appropriate.

Match

Partial objects are not deep clones

Iteratee objects perform per-property checks; they are not a substitute for a custom comparator when you need deep or ordered structure equality.

-1

Always guard before use

Passing -1 into splice or as an object key behaves differently from a valid index; branch on idx !== -1 first.

❓ FAQ

No. It only reads the collection and returns a number (the index) or -1 when nothing matches.
It returns -1, matching the convention of native Array.prototype.findIndex.
Search begins at the resolved index (including support for negative offsets from the end, like other Lodash array helpers). The first match at or after that position wins.
indexOf uses SameValueZero equality against a single search value. findIndex runs your predicate (or iteratee) per element, so you can express arbitrary logic.
Use import findIndex from "lodash/findIndex" or require("lodash/findIndex") for tree-shaking friendly bundles.

Summary

  • Purpose: _.findIndex(collection, predicate, fromIndex) returns the first index where the predicate is truthy, or -1.
  • Safety: the input collection is not mutated by this call.
  • Next: Lodash _.findLastIndex(), _.fill() (earlier in this track), or the array methods hub.
Did you know?

Lodash _.findIndex accepts the same rich iteratee shorthands as other collection methods (functions, property paths, partial objects), while still returning a plain numeric index or -1.

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