The findIndex() method returns the index of the first element that passes your test, or -1 if none match. It pairs naturally with splice and bracket updates. This tutorial covers syntax, five examples, and comparisons with find() and indexOf().
01
Syntax
findIndex(cb)
02
Index
0, 1, 2…
03
No match
-1
04
Stops early
First hit
05
Objects OK
Custom test
06
ES2015
Modern support
Fundamentals
Introduction
Sometimes you need to know where an item lives, not just what it is. Maybe you will update that slot, remove it with splice, or scroll a list to the matching row. findIndex() gives you that position.
It mirrors find() in search logic but returns a number instead of the element. When nothing matches, you get -1—the same convention as indexOf.
Concept
Understanding the findIndex() Method
array.findIndex(callback) walks the array from index 0 upward. For each element it runs your callback with (element, index, array). The first truthy result stops the search and returns that index.
If every callback is falsy, the method returns -1.
💡
Beginner Tip
When you need the value, use find(). When you need the position—for update, delete, or UI focus—use findIndex().
Indexes 0 and 1 fail the test. Index 2 (30) passes, so findIndex returns 2 and stops.
Example 2 — Handle -1 When Nothing Matches
Always check for -1 before using the index in updates or splices.
JavaScript
const numbers = [10, 20, 30, 40, 50];
const index = numbers.findIndex((num) => num > 100);
if (index === -1) {
console.log("No element greater than 100 found.");
} else {
console.log("Found at index:", index);
}
// No element greater than 100 found.
This is a classic reason to choose findIndex over find: you get a numeric slot for assignment or splice without scanning the array twice.
Applications
🚀 Common Use Cases
In-place updates — find index, then assign or splice.
UI selection — highlight the row at the returned index.
Validation — locate the first failing field in an array.
Duplicate checks — find if another item shares a key.
Queue processing — find the first pending job index.
Immutable patterns — combine with spread to replace one slot immutably.
🧠 How findIndex() Runs
1
Start at 0
Iterate indexes in ascending order.
Loop
2
Run callback
Test (element, index, array) at each step.
Predicate
3
Truthy?
Return current index and stop immediately.
Match
4
🔢
End of array
Return -1 if no element passed.
Important
📝 Notes
Returns -1 on failure—same as indexOf, unlike find() which returns undefined.
Index 0 is valid; never use if (index) as a found check.
Short-circuits on the first match; later duplicates are ignored.
Holey arrays may still invoke the callback with undefined at hole indexes.
For the last match, use findLastIndex() (ES2023).
ES2015 method—polyfill needed for Internet Explorer.
Compatibility
Browser & Runtime Support
Array.prototype.findIndex() was added in ES2015 (ES6) alongside find(). It is available in all evergreen browsers and modern Node.js versions.
✓ Baseline · ES2015
Array.prototype.findIndex()
Supported in Chrome 45+, Firefox 25+, Safari 7.1+, Edge 12+, and Node 4+. Not available in Internet Explorer.
97%Modern browser support
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
Array.findIndex()Excellent
Bottom line: Safe for modern web apps. For IE11, use a polyfill or a manual loop that returns -1 when no match is found.
Wrap Up
Conclusion
The findIndex() method bridges search and mutation: you test with a flexible callback and get a numeric position ready for update, delete, or UI focus.
Pair it with explicit -1 checks, and choose find() when you only need the value itself.
Use truthiness on the index (if (index) breaks at 0)
Expect the element—use find() for values
Assume -1 and undefined mean the same thing
Mutate the array unpredictably during the search
Use findIndex when you need every match (filter)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.findIndex()
Your foundation for position-based array searches.
5
Core concepts
📝01
Syntax
arr.findIndex(cb)
API
🔢02
Returns index
Number.
Position
❌03
No match
-1
Sentinel
⚡04
First only
Stops early.
Fast
🔄05
vs find()
Index vs value.
Compare
❓ Frequently Asked Questions
findIndex() returns the index of the first element for which the callback returns a truthy value. If no element matches, it returns -1.
No. findIndex() 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 value used by indexOf and lastIndexOf when a search fails.
findIndex() returns the numeric position (or -1). find() returns the matching element itself (or undefined). Use findIndex when you need to update, remove, or reference a slot by position.
indexOf searches for strict equality (===) with a value. findIndex() accepts any callback predicate, which is essential for objects and complex conditions.
findIndex() is an ES2015 (ES6) feature. All modern browsers support it; Internet Explorer does not.
Did you know?
Index 0 is falsy in JavaScript, so if (arr.findIndex(...)) wrongly treats a match at the start as “not found.” Always compare explicitly: index !== -1.