JavaScript · DEVELOPER GUIDE

JavaScript Arrays: map, filter and reduce

Learn how to transform and summarize JavaScript arrays with practical examples.

Array methods often make data transformations easier to read. Learn what each one returns before chaining them.

map transforms

map returns an array with one result for each input item. It is appropriate when the number of items remains the same.

filter selects

filter keeps items for which the callback returns a truthy value. The original array is not modified by filter.

reduce combines

reduce accumulates values into one result such as a sum, dictionary or grouping. Provide an initial value when empty arrays are possible.

Try an example yourself

Explore a related developer utility and apply what you learned.

Open related tool ↗