Array Map Transform
Predict Output Medium
Question
What does this code print?
Code
let nums = [1, 2, 3];
let doubled = nums.map(n => n * 2);
console.log(doubled);
Hint
map applies the function to each element.
Explanation
map creates a new array by applying the callback to each element. 1*2=2, 2*2=4, 3*2=6. The new array is [2, 4, 6]. The output is: [ 2, 4, 6 ] (Node.js formats arrays with spaces inside brackets).
Related Resources
Related Lessons
- Arrays
Learn how arrays work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.