← TechnologyThe essentials of

filter(): selecting array items without inventing replacements

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 10:06. This is not editorial approval.

In a few sentences

In brief

filter() preserves the elements that fulfill a condition. The result may be shorter than the entrance or it may be empty.

Useful to know

When you want only the records meeting condition , filter() returns a new array with them. The function must return a value, interpreted as truth, for the elements to remain. Rejected entries do not leave empty positions in the result. [1]

For example, const quantities = [0, 3, 0, 8]; const available = quantities.filter(quantity => quantity > 0); gives [3, 8]. This is a conditional stock example. If all values are zero, the result is [], not null or an array of zeros.

The method makes a shallow copy of the selected part. If elements are objects, they do not automatically become independent copies. Changing a property of a selected object can also be seen through the original list. [1]

Before you use it, determine if you're looking for all the matches or just the first one. For the first, find() expresses the intention more precisely; for a list of all suitable records, filter() is the natural choice.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.prototype.filter ↗