我有一个简单的函数来返回符合我的条件的对象。
代码如下:
var res = _.find($state.get(), function(i) {
var match = i.name.match(re);
return match &&
(!i.restrict || i.restrict($rootScope.user));
});
我怎样才能找到所有符合这个标准的结果(不仅仅是第一个),而是所有结果。
感谢您的任何建议。
最佳答案
只需使用 _.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).
关于javascript - lodash _.find 所有匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502450/