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).
collection
predicate
Note: Unlike remove, this method returns a new array.
remove
5.0.0
reject
var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }];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'] Copy
var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }];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']
The collection to iterate over.
Optional
The function invoked per iteration.
Returns the new filtered array.
Iterates over elements of
collection
, returning an array of all elementspredicate
returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).Note: Unlike
remove
, this method returns a new array.Since
5.0.0
See
reject
Example