array of number from 0 to n-1
We can use array of empty values and keys function. Note that
Array(10) generates array of empty values of size 10.
var arr = [...Array(10).keys()] console.log("arr=" + arr);
array of number from 1 to n
In case you need 1 to N array, you can use keys and map on array of empty value. Note that we are using arrow function here which is supported by Chrome and Firefox currently.
var arr = [...Array(10).keys()].map(x => x+1); console.log("arr=" + arr);
The following can also be used:
var arr = [...Array(10)].map((x,i) => i+1); console.log("arr=" + arr);