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
- Use
forEachto log each item. - Use
mapto double numbers. - Use
filterto 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.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →