Discussion: The Arrayist
Execute the code to understand the output and gain insights into the concise method to generate an array of numbers in JavaScript.
We'll cover the following...
Verifying the output
Now, it’s time to execute the code and observe the output.
Press + to interact
const f = (n) => [...Array(n)].map((_, i) => i + 1);console.log(f(20));
Understanding the output
This puzzle reveals a super concise method to generate an array of numbers from 1
to n
using the powerful combination of arrow functions, the spread operator, and the map()
method. ...