Array Map and Filter
map returns a new array by transforming each item. filter keeps items that pass a test. reduce folds a list into one value.
- map keeps the same length.
- filter returns a subset.
- join turns an array into a printable string.
const nums = [1, 2, 3, 4];
const doubled = nums.map((n) => n * 2);
console.log(doubled.join(", "));
After you read this chapter, use Write (when available) and Quiz on this page to lock it in.