CKTIS / JavaScript
Array.prototype.find: the first value matching a condition
find returns the first value whose callback result is truthy, or undefined when no match exists.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
array.find(callbackFn[, thisArg])array.find(callbackFn[, thisArg]) calls callbackFn(value, index, array) from index 0 and stops at the first truthy result, returning the tested value rather than the callback result. With no match it returns undefined, so that result alone cannot distinguish no match from a matched undefined element.
Length is captured initially. Every index in that range is visited, with a sparse hole read as undefined. A later element changed before its visit is observed, while an append beyond the initial length is not. A non-callable callback or null/undefined receiver throws TypeError, and callback exceptions propagate. The example demonstrates early termination and a visited hole.
Examples
const values = [, 4, 8, 12];
const visited = [];
const found = values.find((value, index) => { visited.push(`${index}:${value}`); return value >= 8; });
console.log(found);
console.log(visited.join("|"));Result
8 0:undefined|1:4|2:8