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 runtime.
(我正在寻找以下所有替代方案,以创建一个包含1到N的JavaScript数组,其中N仅在运行时才知道。)
var foo = [];
for (var i = 1; i <= N; i++) {
foo.push(i);
}
To me it feels like there should be a way of doing this without the loop.
(在我看来,应该有一种没有循环的方法。)
ask by Godders translate from so