Skip to main content
Module 6 · Lesson 1 of 421/32 in the course~16 min
Module lessons (1/4)

map and filter

Lesson preview5 hands-on exercises readyJavaScript Course · Module 6 — Functional array methods

Transform every element (map) and select a subset (filter).

What you'll learn in this lesson

  • Transform all elements of an array immutably with .map().
  • Select a subset according to a boolean predicate with .filter().
  • Compose clean pipelines array.filter(...).map(...) without mutating the input data.
  • Avoid the bug of mutating internal objects inside .map (always return new objects with spread).

Overview

.map() and .filter() replace most of the imperative for loops with declarative, side-effect-free pipelines: each method reads the input array and returns a new array, leaving the original intact.

Sections covered in this lesson

  1. 1Mental model: 1-to-1 transformation vs selection
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 4Check for understanding
Pro Lesson · Module 6 — Functional array methods

Unlock "map and filter" and the full JavaScript Course curriculum

Transform every element (map) and select a subset (filter).

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in JavaScript Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.