Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What does Array.from({ length: 3 }) create?

Do you know what will be the output of this code?

JavaScript
console.log(Array.from({ length: 3 }, (_, i) => i * 2));
Show answer and explanation

The answer is [0, 2, 4].

{ length: 3 } is an array-like object with three empty slots. Array.from calls the map function for each index, and i * 2 gives 0, 2, 4.

Take the full quiz Next question →

More Arrays questions

  1. Does the spread operator make a deep copy?
  2. When do default parameters apply in JavaScript?
  3. What is the difference between ?? and || in JavaScript?
  4. How does optional chaining short-circuit in JavaScript?
  5. When do destructuring default values apply?

Related topics