Example 1 — Official: Remove Evens
Predicate removes even numbers; return holds the evens.
var array = [1, 2, 3, 4];
var evens = _.remove(array, function (n) {
return n % 2 == 0;
});
console.log(array);
// → [1, 3]
console.log(evens);
// → [2, 4] How It Works
- Predicate.
n % 2 == 0is truthy for evens. - Collect.
2and4go intoevens. - Mutate. Source shrinks to
[1, 3]. - Return.
evensis a new array — not the same asarray.

