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 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);

All lessons in this course
- map & filter — essentials
- reduce, some/every, find — simple patterns