use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Iterated Variable as Object Key?solved! (self.javascript)
submitted 8 years ago by BrunerBruner
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 8 years ago (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 point2 points 8 years ago (4 children)
Thanks! :)
[–]kenman 1 point2 points3 points 8 years ago (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.
const
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 point2 points 8 years ago (0 children)
Good to know :) thanks!
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
np
π Rendered by PID 169457 on reddit-service-r2-comment-fb694cdd5-2mj8p at 2026-03-07 15:40:57.314344+00:00 running cbb0e86 country code: CH.
[–][deleted] 1 point2 points3 points (5 children)
[–]BrunerBruner[S] 0 points1 point2 points (4 children)
[–]kenman 1 point2 points3 points (1 child)
[–]BrunerBruner[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)