The find()
method accepts a test function
as an argument, and executes the
test function on each element of the array
it is invoked on.
The value of first element of the
array that passes the test function is returned.
The find()
method returns undefined
, in case
no matching elements are found.
In the example given above,
people.find(person => person.age >= 18)
returns the first element that satisfies
the condition person.age >= 18
.