Cycling through JavaScript Objects in a JSON -


i'm requesting data website via post request , isolated needed data/key pair setting

relevant_listings = data["listings"]; 

if print listings console bunch of objects lot of different properties , values:

object {350503275519564011: object, 359510012249522033: object, 358384527390382582: object, 826758911669189345: object, 827884358724814556: object…} 

i know how access properties first object returned:

for (var key in relevant_listings) {         console.log(relevant_listings[key]["property1"]); 

however can't find way cycle through different objects , property1 second object example.

would kind me out correct syntax/way approach this?

kind regards,

if use single for loop cycle though parent object won't able access child object's properties. can, among many strategies, use nested loops. instance,

var data = {     obj1: {         dog: "retriever",         name: "bob"     },     obj2: {         dog: "poodle",         name: "jim"     } };  (var p in data) {     console.log(p) //"obj1", "obj2"     console.log(data[p]) //this doesn't access child properties of nested object      //check if property of parent object nested object     if (typeof data[p] === "object") {          /**          * way write nested loop          * var nestedobject = data[p];          * (var q in nestedobject) { //etc.... }          */          (var q in data[p]) {             console.log(data[p][q]) //"retriever", "bob", "poodle", "jim"         }     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -