javascript - Nested forEach loop does not work -


i have data in json object array. i'm trying use nested foreach loops extract data.

the data modeled belo. there's multiple datamodels , multiple childnodes inside datamodels.

//this example data looks datamodels[0].childnodes[0].appid 

i trying following:

datamodels.foreach(function(entry){     entry.foreach(function(childrenentry){       console.log(childrenentry.appid);     }) }) 

the above not work , gives me error saying 'entry' not function. there better way achieve i'm trying do?

you not targeting array inside entry object, need loop on childnodes property in order data want. see example below.

var datamodels = [];  datamodels[0] = {     childnodes: [] };  datamodels[0].childnodes[0] = {     appid: "foo" };  datamodels.foreach(function(entry){      entry.childnodes.foreach(function(childrenentry) { // missing )       console.log(childrenentry.appid);     }); }); 

jsfiddle demo


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -