Use lodash _.filter
method:
_.filter(collection, [predicate=_.identity])
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).
with predicate as custom function
_.filter(myArr, function(o) {
return o.name == 'john';
});
with predicate as part of filtered object (the _.matches
iteratee shorthand)
_.filter(myArr, {name: 'john'});
with predicate as [key, value] array (the _.matchesProperty
iteratee shorthand.)
_.filter(myArr, ['name', 'John']);
Docs reference: https://lodash.com/docs/4.17.4#filter
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…