Function Updated 17 Oct 2026
Array.findIndex(callback)
Returns the index of the first item for which the function returns a truthy value.
Parameters
callbackfunctionrequiredFunction called with (item, index, array). Return a truthy value for the item you want.
Returns
The index (zero-based), or -1 if no item matches.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
const users = [{ id: 7, name: "Kari" }, { id: 9, name: "Ola" }];
write(users.findIndex(u => u.id === 9)); // 1
write("\n");
write(users.findIndex(u => u.id === 42)); // -1The JavaScript above produces this output:
1
-1