filter()

noun

say it: “FIL-ter” /ˈfɪltər/

The JavaScript array method that keeps only the items that pass a test, in a new array.

What does filter() do in JavaScript?

filter() — Keeps only the items that pass a test.

const prices = [2, 7, 3];
const affordable = prices.filter(price => price < 5);

In a sentence

  • “products.filter(p => p.price < 10) gave just the cheap products.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects