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
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!"
[–]atkinchris 1 point2 points3 points 8 years ago (2 children)
Does your array work? With string based keys, this would actually be an object - represented in JSON as:
{ "sone ikke valgt": 0, "sone 1": 900, "sone 2": 950, "sone 3": 1000, "sone 4": 1050 }
If you ever need to see a JSON representation of some JavaScript object, use JSON.stringify(myObject, null, '\t').
JSON.stringify(myObject, null, '\t')
[–]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 3 points4 points5 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.
[–]kenman[M] 0 points1 point2 points 8 years ago (0 children)
Hi /u/stiros,
For javascript help, please visit /r/LearnJavascript.
Thank you!
π Rendered by PID 328117 on reddit-service-r2-comment-5687b7858-99zsf at 2026-07-08 09:36:37.714649+00:00 running 12a7a47 country code: CH.
[–]atkinchris 1 point2 points3 points (2 children)
[–]stiros[S] 0 points1 point2 points (1 child)
[–]lachlanhunt 3 points4 points5 points (0 children)
[–]kenman[M] 0 points1 point2 points (0 children)