Without a for loop, here is a solution:
Array.apply(0, Array(8)).map(function() { return 1; })
The explanation follows.
Array(8)
produces a sparse array with 8 elements, all undefined
. The apply
trick will turn it into a dense array. Finally, with map
, we replace that undefined
the (same) value of 1
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…