1Array.from(Array(10).keys())
2//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
3
4[...Array(10).keys()]
5//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
6
7Array.from({length: 10}, (_, i) => i + 1)
8//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1function range(start, end) {
2 return Array(end - start + 1).fill().map((_, idx) => start + idx)
3}
4var result = range(9, 18); // [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
5console.log(result);
1// Javascript create array from 1 to n
2
3[...Array(n+1).keys()].slice(1)
4
5// E.g. for n = 10:
6// [...Array(11).keys()].slice(1)
7// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1for (i of range(1, 5)) {
2 console.log(i);
3}
4/* Output
5 * 1 2 3 4 5 */
6
7[...range(1, 5)] // [1, 2, 3, 4, 5]
8