The _.find()
method in lodash
is used to locate objects in an array that meet a set of requirements.
This method loops through every element in the collection and returns the first element for which the callback returns true.
_.find(collection, [callback=identity])
collection
: This is the collection to iterate over.callback
: This is the function that’s called per iteration.The method returns the found element. Otherwise, it is undefined.
Let’s look at the code below:
In the HTML tab:
lodash
script.In the JavaScript tab:
_.find()
method to find the object to be located.