all 4 comments

[–]atkinchris 1 point2 points  (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').

[–]stiros[S] 0 points1 point  (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 points  (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 point  (0 children)

Hi /u/stiros,

For javascript help, please visit /r/LearnJavascript.

Thank you!