Skip to content
dreamcode
dreamcode
Map
Array methods
Lesson 17 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 4 · JS Collections Depth

Map and Filter

JavaScript arrays have built-in helper functions: .map() (creates a new array by transforming each element) and .filter() (creates a new array keeping only elements that match a check).

Worked example

How it reads

  • **nums.map(n => n * 2)** loops over elements and returns their doubled values
  • nums.filter(n => n % 2 === 0) filters elements returning only those matching the condition
Cloud tip: These methods do not modify the original array; they return a brand new array, helping you keep your data safe.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Use filter to keep only heights of at least 2000, then map them to kilometres (divide by 1000). Log the result: [ 2, 3 ].

Press Run to check your work.