Similar to _.indexOf, but returns the first index where a predicate truth test passes; otherwise -1 (official Underscore docs). Stable Array helper — not deprecated.
Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.findIndex. Start with this line.
Underscore
_.findIndex(array, predicate, [context])
Call
What it does
_.findIndex(array, predicate, [context])
Primary signature.
_.findIndex(...)
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
_.findIndex(array, predicate, [context])
Parameters
Parameter
Description
array
Required. List to search left to right
predicate
Required. Function / iteratee; truthy = match
context
Optional. this binding for the predicate
Return Value
Return Value
Description
*
Index number, or -1
Underscore.js Examples
Example 1 — Official: First Matching Index
Find the index of the first prime number.
Underscore
function isPrime(n) {
if (n < 2) return false;
for (var i = 2; i * i <= n; i++) {
if (n % i === 0) return false;
}
return true;
}
_.findIndex([4, 6, 7, 12], isPrime);
// → 2
Matcher shorthand.{ id: 2 } becomes a predicate that checks those properties.
First match. Grace has id: 2 at index 1.
Same idea as findWhere. See _.findWhere for the element itself.
Still returns -1 when no object matches the properties.
Compatibility
Browser & Runtime Support
_.findIndex 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.
✓ Stable · Underscore 1.x
_.findIndex()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded. Native Array.prototype.findIndex is similar but separate.
100%With Underscore 1.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.findIndexUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not the same as native Array.prototype.findIndex — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.findIndex(array, predicate, [context]) returns the first index where the predicate truth test passes; otherwise -1. Official example: _.findIndex([4, 6, 7, 12], isPrime) → 2.
It returns -1. Check with index !== -1 before using the index to update or splice.
_.indexOf looks for a specific value with ===. _.findIndex runs a predicate against each item and returns the index of the first that passes.
_.find returns the matching element; _.findIndex returns its position. Use findIndex when you need the index.
Yes. Pass a predicate like function (user) { return user.id === 3; }, or an iteratee shorthand such as { id: 3 }.