Example 1 — Keep Numbers Greater Than Zero
Official simple filter: drop zeros and negatives.
var result = $.grep([0, 1, 2], function (n) {
return n > 0;
});
console.log(result); // [1, 2] How It Works
- Source. Start with
[0, 1, 2]. - Test. Callback returns
trueonly whenn > 0. - Keep.
1and2pass;0fails.

