I want to create an array with numbers from 1
to n
. For example if my n
number is 8
I need my list
array to be:
[1,2,3,4,5,6,7,8]
Of course it could be done with for
loop, like so:
var n = 8;
var list = [];
for(var i=1;i!=n+1;i++){
list.push(i);
}
But is there some unique way to do this?
I have also tried new Array(8)
but it didn't do what it need:
[ , , , , , , , ]