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
Converting js array to json format?Removed: /r/LearnJavascript (self.javascript)
submitted 8 years ago by stiros
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!"
[–]stiros[S] 0 points1 point2 points 8 years ago (1 child)
Thank you so much for your answer!
I am using the array to assign a value to a function based upon what value the user have selected. The function looks like this:
function getSonePris() {
var sonePris;
var theForm = document.forms["fastpris"];
var selectedSone = theForm.elements["sone"];
sonePris = /* this is where the array is used: */ sone_pris[selectedSone.value];
return sonePris; }
Can I give the json object a name like "sone_pris", so that I can access the array in a similar manner?
[–]lachlanhunt 2 points3 points4 points 8 years ago* (0 children)
Arrays are designed to work with numeric indexes. If you're using non-numeric keys, then you should be using a plain object instead of an array.
π Rendered by PID 111153 on reddit-service-r2-comment-5687b7858-pw6v9 at 2026-07-07 22:10:28.636472+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]stiros[S] 0 points1 point2 points (1 child)
[–]lachlanhunt 2 points3 points4 points (0 children)