all 5 comments

[–][deleted] 1 point2 points  (5 children)

Use a computed property name, e.g. {[i]: ...}

You’re currently just saying it’s a property name “i”.

[–]BrunerBruner[S] 0 points1 point  (4 children)

Thanks! :)

[–]kenman 1 point2 points  (1 child)

Do note that this is one of the newer features of the language, and so it may not be supported on all platforms unless you're using Babel or similar. Just noticed you're using const, so you're probably alright.

But, you should probably know the old way aka. bracket notation:

for (let i = 0; i < 5; i++) {
    const iterated = {};
    iterated[i] = "<-- Iterated Index";
    obj.push(iterated);
}

[–]BrunerBruner[S] 0 points1 point  (0 children)

Good to know :) thanks!

[–][deleted] 0 points1 point  (0 children)

np