JavaScript Array findIndex() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.findIndex(callback) returns the index of the first element that passes your test. No match → -1. It stops early and does not mutate the array (ES2015).

Remember
array.findIndex((element, index, array) => test)

first truthy match → that index (0-based)
no match → -1
stops at the first hit

find()      → the element (or undefined)
indexOf(x)  → index by === equality only

Syntax

Call array.findIndex. Start with this line.

JavaScript
array.findIndex(callback, thisArg?)
CallWhat it does
array.findIndex(callback, thisArg?)Primary signature.
array.findIndex(...)Call with the arguments your case needs.

Built into JavaScript. Call findIndex(...) on an array instance — no import required.

Library declarations
JavaScript
array.findIndex(callback, thisArg?)

Parameters

ParameterDescription
callbackRequired. Test function; truthy → return that index
index, arrayOptional. Extra callback args when needed

Return Value

Return ValueDescription
*Index ≥ 0, or -1

JavaScript Examples

Example 1 — Index of the First Match

Get the position of the first number greater than 25.

JavaScript
const numbers = [10, 20, 30, 40, 50];
const index = numbers.findIndex((num) => num > 25);

console.log(index);           // 2
console.log(numbers[index]);  // 30
Try It Yourself

How It Works

  1. Scan from the left. Starts at index 0.
  2. Skip 10 and 20. Both fail > 25.
  3. Hit 30. First truthy test → return index 2.
  4. Use the index. numbers[2] reads the matching value.

Example 2 — Handle -1 When Nothing Matches

Always check for -1 before indexing into the array.

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);
}
Try It Yourself

How It Works

  1. Test every element. None are greater than 100.
  2. Return -1. Same “not found” sentinel as indexOf.
  3. Guard before use. Never do arr[-1] as a lookup—check first.
  4. Show a fallback. Print a clear message when the search fails.

Example 3 — Index of an Object by Property

Find where "Bob" sits—then you can update or remove that slot.

JavaScript
const users = [
  { id: 1, name: "Alice" },

  { id: 2, name: "Bob" },

  { id: 3, name: "Charlie" }
];

const index = users.findIndex((user) => user.name === "Bob");

console.log(index);         // 1
console.log(users[index]);  // { id: 2, name: "Bob" }
Try It Yourself

How It Works

  1. Objects need a predicate. indexOf cannot match by name.
  2. Compare a property. Callback checks user.name === "Bob".
  3. Get position 1. Bob is the second element (0-based).
  4. Index unlocks edits. Use it with assignment, splice, or similar.

Browser & Runtime Support

Array.prototype.findIndex() is part of ES2015 (ES6). It has been available in evergreen browsers for years and in Node.js since version 4.

✓ Baseline · ES2015

Array.prototype.findIndex()

Supported in Chrome 45+, Firefox 25+, Safari 7.1+, Edge 12+, and Node 4+. Not available in Internet Explorer.

98% Modern browser support
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
Array.findIndex() Excellent

Bottom line: Safe for modern web and Node targets. Polyfill only if you must support Internet Explorer.

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.

Next: findLast()

Find the first match when scanning from the end of the array.

findLast() 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.

11 people found this page helpful