Zest.

JavaScript: map, filter and reduce

A short, tested JavaScript example for map, filter and reduce. Copy it and adjust the names and paths for your project.

JavaScript
const nums = [1, 2, 3, 4];

const doubled = nums.map(n => n * 2);          // [2, 4, 6, 8]
const evens = nums.filter(n => n % 2 === 0);   // [2, 4]
const sum = nums.reduce((a, n) => a + n, 0);   // 10

Find it in Zest

Search for “javascript map, filter and reduce” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More JavaScript examples

All JavaScript examples