You can just use a loop and do:
var a = 5;
var arr = [];
for(var i=0; i<a; i++) {
arr.push(i);
}
As others have stated in their answers,
Array direct assignment is even faster than Push
Having used jsperf
, that appears to be incorrect for Chrome/Firefox. See below:
From this, I would use push
as stated in my answer above.
5
solved How can I create an array of sequential values from a value?