# 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.

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

## In a sentence

- “products.**filter**(p => p.price &lt; 10) gave just the cheap products.”

Level: Journeyman · [More JavaScript terms at this level](https://www.ask-codey.com/glossary?category=javascript&level=3)

Updated: November 9, 2026

## In other subjects

- [filter() in Java](https://www.ask-codey.com/glossary/filter-java)
- [filter() in Python](https://www.ask-codey.com/glossary/filter)

Source: https://www.ask-codey.com/glossary/filter-javascript
