JavaScript (ES2026) reference · Array Methods

JavaScript Array find() Method

Return the first element that passes a test function, or undefined if none does.

JavaScript (ES2026) Since ES2015

Syntax

array.find(callbackFn, thisArg)

Parameters

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

Return value

The first matching element, or undefined.

Examples

Find an object by idTry it yourself
const users = [{ id: 1, name: "Ada" }, { id: 2, name: "Linus" }];
console.log(users.find((u) => u.id === 2));
console.log(users.find((u) => u.id === 9));

Output

{ id: 2, name: 'Linus' }
undefined
find() vs filter()Try it yourself
const nums = [3, 10, 18];
console.log(nums.find((n) => n > 5), nums.filter((n) => n > 5));

Output

10 [ 10, 18 ]

Version history

VersionChange
JavaScript ES2015Added

In other languages