Andurit Andurit - 6 months ago 186
Javascript Question

lodash _.find all matches

I have simple function to return me object which meets my criteria.

Code looks like:

var res = _.find($state.get(), function(i) {
var match = i.name.match(re);
return match &&
(!i.restrict || i.restrict($rootScope.user));
});


How can I find all results (not just first) which meets this criteria but all results.

Thanks for anz advise.

Answer

just use _.filter - it returns all matched items

Comments