Actually, there's a simple way to create a [0..N)
(i.e., not including N
) range:
var range0toN = Object.keys(Array.apply(0,Array(N)));
Apparently Object.keys
part can be dropped if you only want to get a proper array of N elements.
Still, like others said, in this particular case it's probably better to use for
loop instead.