arrays - Get specific values form JSON Table with javascript over IDs -


i have following problem:

i have json table data need (found on internet since need)

var testext ={"key1":[         {             "firstname":"ray",             "lastname":"villalobos",             "joined":2012         },         {             "firstname":"john",             "lastname":"jones",             "joined":2010         } ]}  document.getelementbyid("demo").innerhtml=testext.key1[0].firstname; 

this works fine can see still need index [0] dataset need.

i need to without index...

like here:

var testext = {  "key1": ["string1/1", "string1/2" ],  "key2": ["string2/1", "strin2/2"]   };    document.getelementbyid("demo").innerhtml = testext['key1'][0]; 

just combined variable :

document.getelementbyid("demo").innerhtml = testext['key1'].['firstname']; 

anyone idea on how can this?

thanks in advance.

you correct. restructure array associative array of associative arrays. can call them array_name['first_index']['second_index'].

var testext = {    "key1": {      "firstname": "ray",      "lastname": "villalobos",      "joined": 2012    },    "key2": {      "firstname": "john",      "lastname": "jones",      "joined": 2010    }  };    document.getelementbyid("demo").innerhtml = testext['key1']['firstname'];
<div id="demo">default</div>


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -