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.
Overview. The _. get() method in Lodash retrieves the object's value at a specific path. If the value is not present at the object's specific path, it will be resolved as undefined . This method will return the default value if specified in such a case.
The _. find() function looks at each element of the list and returns the first occurrence of the element that satisfy the condition. If any element of list is not satisfy the condition then it returns the undefined value. Syntax: _.find(list, predicate, [context])
isEqual() Method. The Lodash _. isEqual() Method performs a deep comparison between two values to determine if they are equivalent. This method supports comparing arrays, array buffers, boolean, date objects, maps, numbers, objects, regex, sets, strings, symbols, and typed arrays.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With