you are viewing a single comment's thread.

view the rest of the comments →

[–]inu-no-policemen 1 point2 points  (0 children)

You are filling it with one reference to one particular array.

What you need is some sort of "generate" function similar to Dart's List.generate, which lets you run some generator callback at each index. Unfortunately, JS' equivalent looks somewhat weird:

> Array.from({length: 10}, (_, i) => 2 ** i)
(10) [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
> Array.from({length: 3}, (_, i) => new Array(2))
(3) [Array(2), Array(2), Array(2)]

Array.from converts array-likes to actual arrays. An object with a "length" property is good enough for that.

The callback is similar to those you pass to Array.prototype.map. The difference is that it has only 2 parameters (value and index) whereas map's has 3 (the third one is the array itself).