Array Map in JavaScript
Level 382 keystrokes
This uses map to create a new array with each number doubled.
JavaScript code
// Create an array of numbers1let nums = [1, 2, 3, 4];// map() builds a new array by applying n => n * 2 to each element// nums stays unchanged; doubled is a new array2let doubled = nums.map(n => n * 2);// Outputs [2, 4, 6, 8]3console.log(doubled);Output
[ 2, 4, 6, 8 ]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
,× 3;× 3=× 3.× 2(× 2)× 2[× 1]× 1*× 1>× 1