Reputation: 55
Sorry if the title is misleading, had no idea on how to title it.
Here's a var :
var rects = [
{x: 32, y: 32, w: 32, h: 32},
{x: 32, y: 32, w: 32, h: 32},
{x: 0, y: 0, w: 32, h: 32}
], i = 0, r;
Now, I want to do something like this :
for (nb = 0; nb > 10; nb++;) {
var rects = [ {x: 32 * nb, y: 32 * nb, w: 32, h: 32} ], i = 0, r;
}
(Of course this doesn't work).
How can I do this ? Thanks !
Upvotes: 0
Views: 56
Reputation: 138367
Either use Array.from
:
let rects = Array.from({length:3} , _=>({x: 32, y: 32, w: 32, h: 32})), i = 0, r;
Or use a traditional for loop:
let rects = [], i = 0, r;
for(let index = 0; index < 3; index++)
rects[index] = {x: 32, y: 32, w: 32, h: 32};
Upvotes: 1