Answers for "create array with 1 to n elements javascript"

14

linux install node

sudo apt install nodejs
Posted by: Guest on April-28-2020
2

create an array from 1 to n javascript

Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[...Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Array.from({length: 10}, (_, i) => i + 1)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Posted by: Guest on October-28-2020

Code answers related to "create array with 1 to n elements javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language