# filter()

Keeps only the items that pass a test.

## 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);
```

Level: Journeyman · [More JavaScript terms at this level](https://www.ask-codey.com/glossary/subjects/javascript/journeyman)

Updated: September 27, 2026

## In other subjects

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

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