0Pricing
JavaScript Academy · Lesson

map & filter — essentials

Transform and select data with map and filter; chain them and avoid mutation for safer code.

Intro to map & filter

Goal: Transform items with map and pick items with filter.

  • map: transform
  • filter: select
  • Chain map → filter
  • No mutation
map & filter — essentials — illustration 1

map basics

map applies a function to every element and returns a new array (same length).

// map transforms each value and returns a new array
const nums = [1, 2, 3];

const doubled = nums.map(function (n) {
  return n * 2;
});

console.log("nums:", nums);
console.log("doubled:", doubled);
map & filter — essentials — illustration 2

All lessons in this course

  1. map & filter — essentials
  2. reduce, some/every, find — simple patterns
← Back to JavaScript Academy