EN
JavaScript - generate range of numbers from 0 to n
0 points
In this article, we would like to show you how to generate a range of numbers from 0
to n
in JavaScript.
Quick solution:
xxxxxxxxxx
1
const n = 3;
2
const array = [Array(n).keys()];
3
4
console.log(array); // [ 0, 1, 2 ]
or:
xxxxxxxxxx
1
const n = 3;
2
const array = Array.from(Array(n).keys());
3
4
console.log(array); // [ 0, 1, 2 ]