The following code creates and fills an array with numbers 0 to 9
[...Array(10).keys()]
Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
If you want the numbers from 1 to 10:
[...Array(10).keys()].map(i => i+1)
Result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Or this should work as well:
Array(10).fill().map((v,i) => i+1)
Result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Top comments (0)