← JavaScript Foundations
15 / 26
Lesson 15 — map & filter
Keep some, change all
filter keeps only the items that pass a test; map turns every item into a new one. Both return a new array and leave the original alone, so you can chain them.
[1, 2, 3, 4].filter((x) => x % 2 === 0); // [2, 4]
[2, 4].map((x) => x * 10); // [20, 40]
x % 2 === 0 means "x divided by 2 leaves no remainder" — x is even.
Why it matters: this is how modern JavaScript reshapes data, and it is everywhere in React.
Want it another way?
Task
From 1..6 keep the even numbers and double them, then log the result joined with commas.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.