![]() |
VOOZH | about |
The Lodash _.find() method searches through a collection (array or object) and returns the first element that satisfies a specified condition (predicate). It’s useful for quickly locating a matching item within a collection. If no match is found, it returns undefined.
_.find(collection, predicate, [fromIndex=0])It returns the matched element or undefined if nothing matches.
Example: In this example, we are passing the array and a function in the _.find() method which returns the matched first value.
Output:
2Example 2: In this example, we will search for the first student (object) in the list who has more scores than 90.
Output:
{name: 'Akhil', marks: '98' }Example 3: In this example, we are getting 'undefined' as there is no matched value present in the array according to the function.
Output:
undefined