Example 1 — Official Docs Evens
Keep every even number from 1 through 6.
var evens = _.filter([1, 2, 3, 4, 5, 6], function (num) {
return num % 2 == 0;
});
evens;
// → [2, 4, 6] How It Works
- Test. Predicate returns
truefor even numbers. - Keep.
2,4, and6are pushed into a new array. - Skip. Odds are ignored.
- Docs sample. This is the official Underscore example.

