javascript - Looping through a JSON Array gives "undefined" results -


this question has answer here:

i have json string being parsed (in response var) ajax:

the json

{    "thearray":[         {            "almostthere": {               "whatwearelookingfor":"hello"          }       },       {         "almostthere": {             "whatwearelookingfor":"goodbye"         }       }    ] } 

the json being parsed

var jsondata = json.parse(response); //response string version of json code! 

now, need loop json array, hereby mentioned thearray. this:

looping thearray

for (var contents in jsondata["thearray"]) {  } 

and inside there, value of whatwearelookingfor element:

for (var contents in jsondata["thearray"]) {     console.log(contents.whatwearelookingfor + "!"); } 

but there catch! console outputs... undefined!. - have tried multiple ways make work, such using contents["whatwearelookingfor"] , what-not, still same results.

you forgot access almostthere

  jsondata.thearray[i].almostthere.whatwearelookingfor 

for (var = 0; < jsondata.thearray.length; i++) {     console.log(jsondata.thearray[i].almostthere.whatwearelookingfor); } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -