JavaScript (ES2026) reference · Array Methods
JavaScript Array findIndex() Method
Return the index of the first element that passes a test function, or -1 if none does.
JavaScript (ES2026) Since ES2015
Syntax
array.findIndex(callbackFn, thisArg)
Parameters
| Parameter | Description |
|---|---|
callbackFn |
Called for each element with (element, index, array). |
Return value
An index, or -1.
Examples
const tasks = [{ done: true }, { done: false }, { done: false }];
console.log(tasks.findIndex((t) => !t.done));
Output
1
const list = ["a", "b"];
const i = list.findIndex((x) => x === "z");
console.log(i === -1 ? "not found" : i);
Output
not found
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
array.find()· Return the first element that passes a test function, or undefined if none does.array.indexOf()· Return the first index at which a value is found (using ===), or -1 if it isn't in the array.array.findLastIndex()· Return the index of the last element that passes a test function, or -1 if none does.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial