Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.findIndex: index of the first match

findIndex returns the first index whose callback is truthy, or -1; it also visits sparse holes as undefined.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.findIndex(callbackFn[, thisArg])

array.findIndex(callbackFn[, thisArg]) calls callbackFn(value, index, array) in ascending order and returns the integer index at the first truthy result. It does not return the element value. No match has the unambiguous result -1, so a matched undefined is not confused with failure.

Length is established initially, but every index in that range—including a hole read as undefined—is visited. Changes made before a visit are visible; later appended indexes are not. A non-callable callback or nullish receiver throws TypeError, and a callback exception aborts the method. The example deliberately finds a hole and separately demonstrates -1.

Examples

const values = ["A", , "C"];
console.log(values.findIndex(value => value === undefined));
console.log(values.findIndex(value => value === "missing"));

Result

1
-1

Sources