bhylu.com

Advertisements

JS Array Iterations

Map transforms each item into a new item. Filter keeps matching items, and reduce combines items into one result.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const prices = [4, 7, 12];
const affordable = prices.filter(price => price < 10);
console.log(affordable.map(price => price * 2));

What happens

The affordable values become [8,14].