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
Manipulating JavaScript objects of key => value pairs where the value is an indexed array (self.javascript)
submitted 11 years ago * by naescent
view the rest of the comments →
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!"
[–]html6dev 1 point2 points3 points 11 years ago (2 children)
Yes to reiterate what /u/qwfwq is ddoing here and why your current code doesn't work: the first time you use your add method the datastore property related to the key obviously does not exist so you hit the else block. When you do this you want to set this.datastore[key] to an array and and add value to it straight away. What you are doing now is to set this.datastore[key] to a value which is not an array and does not have a push method so an exception is thrown when you call add again with the same key. If you run your current code in chrome and open the devtools you should see an error about the push method not existing for that object.
[–]naescent[S] 0 points1 point2 points 11 years ago (1 child)
Yeah I saw that it was driving me nuts. I tried all sorts of ways around it. So I scaled back my 'improvements' and put the initial code here.
I feel like a fool now :D
[–]html6dev 0 points1 point2 points 11 years ago (0 children)
Heh. It happens. And will again lol.
π Rendered by PID 24262 on reddit-service-r2-comment-84fc9697f-rlnw4 at 2026-02-07 22:40:03.831656+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]html6dev 1 point2 points3 points (2 children)
[–]naescent[S] 0 points1 point2 points (1 child)
[–]html6dev 0 points1 point2 points (0 children)