Home/Tutorials/JavaScript/Array Map and Filter

0 of 3 saved

JavaScript5 min read

Array Map and Filter

Read this chapter, write the program on this page, then pass a short check to open the next one.

Transform and filter lists.

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.