LESSON 20

Array Methods

Learning objective: Transform arrays with map, filter, and forEach.

Understand

Array methods process lists cleanly without manual loops.

forEach runs a function on each item, map builds a new transformed array, and filter keeps items that pass a test. These make list processing concise and readable.

Analogy: These methods are like an assembly line: each item passes through and is handled the same way.

See It in Action

Mapping and filtering:

const nums = [1, 2, 3, 4];
const doubled = nums.map(n => n * 2);
const evens = nums.filter(n => n % 2 === 0);
How it works: map returns [2,4,6,8] and filter returns [2,4], each without changing the original array.

Try It Yourself

  1. Use forEach to log each item.
  2. Use map to double numbers.
  3. Use filter to keep only some items.

Quick Quiz

What does map return?

Challenge

Take an array of numbers and produce a new array of only the even ones.

Success condition: Your code returns a correctly filtered array without altering the original.