Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  182] [ 1]  / answers: 1 / hits: 84681  / 8 Years ago, fri, february 19, 2016, 12:00:00

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 any advise.


More From » lodash

 Answers
78

Just use _.filter - it returns all matched items.



_.filter




Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).



[#63258] Wednesday, February 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keana

Total Points: 452
Total Questions: 97
Total Answers: 81

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
;