Filter
Filter
π¨βπΌ The
filter method creates a new array with only elements that pass a
test.const numbers = [1, 2, 3, 4, 5]
const evens = numbers.filter((n) => n % 2 === 0)
// [2, 4]
The callback returns
true to keep the element or false to exclude it.π¨ Open
and:
- Filter products by category
- Filter products by price range
- Chain
filterwithmap
π°
filter keeps items where your callback returns true.