DEV Community

Discussion on: How to Create an Array Containing 1 to N in JavaScript

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

There are more ways. Examples:

new Array(1000).fill(0).map((_, i) => i + 1);

[...new Array(1000)].map((_, i) => i + 1);
Enter fullscreen mode Exit fullscreen mode

Also one more Note:

const numbers = Array.from(
    {length: 1000},
    (item, index) => item = index + 1
);
Enter fullscreen mode Exit fullscreen mode

This make no sense because you're mutating value (item) that is throw away. use (_, index) => index + 1

Collapse
 
alfredosalzillo profile image
Alfredo Salzillo

I think this is only another article written by someone only to show that he have written one.