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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.findIndex(callbackFn, thisArg)

Parameters

ParameterDescription
callbackFn Called for each element with (element, index, array).

Return value

An index, or -1.

Examples

First unfinished taskTry it yourself
const tasks = [{ done: true }, { done: false }, { done: false }];
console.log(tasks.findIndex((t) => !t.done));

Output

1
Check for -1Try it yourself
const list = ["a", "b"];
const i = list.findIndex((x) => x === "z");
console.log(i === -1 ? "not found" : i);

Output

not found

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?