_.find() in Underscore.js

This is the Undescore.js library function that allows us to iterate over your collection and finding the value in that collection based on the algorithm implemented. Following is the way we can use this function.

var numbers = [1, 2, 3, 4, 5];
var found = _.find(numbers, function(number){
return number % 2 == 0;
});
console.log(found);

output

[2, 4]

Leave a comment

Your email address will not be published. Required fields are marked *