lodash 經常使用方法。

_.filter(collection, [predicate=_.identity])

遍歷 collection(集合)元素,返回 predicate(斷言函數)返回真值 的全部元素的數組。 predicate(斷言函數)調用三個參數:(value, index|key, collection)。 數組

_.filter(users, function(o) { return !o.active; });
// => objects for ['fred']
 
// The `_.matches` iteratee shorthand.
_.filter(users, { 'age': 36, 'active': true });
// => objects for ['barney']
 
// The `_.matchesProperty` iteratee shorthand.
_.filter(users, ['active', false]);
// => objects for ['fred']
 
// The `_.property` iteratee shorthand.
_.filter(users, 'active');
// => objects for ['barney']
相關文章
相關標籤/搜索