JavaScript Array.prototype.find() Method
The find() method returns the first element in an array that passes a test, or undefined if no element does.
Description
The find() method returns the first element for which the callback returns a truthy value, and stops searching as soon as it finds it. If nothing matches, it returns undefined.
It is the usual way to look up an object by a property, such as a user by ID. Use findIndex() if you need the position, findLast() to search from the end, filter() for all matches, and includes() to check for a specific value.
Because it returns the element itself, find() gives you a reference to the original object, so changing its properties changes the object in the array. If the array can legitimately contain undefined, you can't tell "not found" from "found undefined"; use findIndex() in that case. The callback is called for every index, including empty slots.
Syntax
array.find(callbackFn)
array.find(callbackFn, thisArg)Parameters
- callbackFnA function called for each element, receiving
element,indexandarray. - thisArgOptional. A value to use as
thisinsidecallbackFn.
Return Value
The first element that passes the test, or undefined if none does.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.find() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





