I\'m looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runt
1
N
You can use this:
new Array(/*any number which you want*/) .join().split(',') .map(function(item, index){ return ++index;})
for example
new Array(10) .join().split(',') .map(function(item, index){ return ++index;})
will create following array:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]