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
| Parameter | Description |
|---|---|
callbackFn |
Called for each element with (element, index, array). |
Return value
The first matching element, or undefined.
Examples
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' }
undefinedconst nums = [3, 10, 18];
console.log(nums.find((n) => n > 5), nums.filter((n) => n > 5));
Output
10 [ 10, 18 ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
next()· Python
Related
array.findIndex()· Return the index of the first element that passes a test function, or -1 if none does.array.findLast()· Return the last element that passes a test function, searching from the end, or undefined if none does.array.filter()· Return a new array with only the elements that pass a test function. The original array is not changed.array.includes()· Return true if the array contains a value, using SameValueZero equality (so it finds NaN, unlike indexOf).- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial