Returns the new filtered array.
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']
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).
Note: Unlike remove
, this method returns a new array.
The collection to iterate over.
Optional
predicate: anyThe function invoked per iteration.
Returns the new filtered array.
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']
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.