Array.prototype.find()
array.find(callback(element, index, array), thisArg)
Goes through the array from the start and returns the first element for which the function returns a truthy value. It does not look at the following elements.
Parameters
- callback(element, index, array) – a function called for each element: the element, its index and the whole array (the index and the array are optional).
- thisArg – optional, the value of
thisinside the function.
Return value
The found element, or undefined when none matches.
Examples
const customers = [
{ id: 1, name: 'Jane Miller' },
{ id: 2, name: 'Peter Smith' },
];
console.log(customers.find((c) => c.id === 2));
console.log(customers.find((c) => c.id === 9));
console.log(customers.find((c) => c.id === 9)?.name ?? 'unknown');
Output:
{ id: 2, name: 'Peter Smith' }
undefined
unknown
Things to watch out for
- The result
undefineddoes not tell “not found” from a found element with the valueundefined. When that matters, use findIndex(). - It returns the element itself (for an object a reference to the same object), filter() always returns an array.
- It searches from the start; findLast() searches from the end.
Browser support
Baseline – widely available: in all major browsers since September 2015, considered widely available since March 2018. Since version: Chrome 45, Firefox 25, Safari 8; Node.js 4.0.0. As of October 2026 (MDN browser-compat-data).
Related:
Array.prototype.findIndex()
Array.prototype.findLast()
Array.prototype.filter()
Array.prototype.some()
Array.prototype.includes()