</> CodeWithMe
Sign in
← ⚡ JavaScript from Scratch

Arrays and map

An array is an ordered list of values:

const fruits = ["apple", "banana"];
console.log(fruits.length); // 2
console.log(fruits[0]);     // apple

The map method creates a new array by applying a function to every element:

const nums = [1, 2, 3];
const plusOne = nums.map((n) => n + 1); // [2, 3, 4]

Challenge

Write a function doubleAll(arr) that returns a new array with every number multiplied by 2.