I am trying to walk throught this tree and print all the "element" objects but its not working with me
var config = {
"tree": {
"element": {
"name": "pd",
"children": {
"element": {
"name": "pd2",
"children": {}
},
"element": {
"name": "pd3",
"children": {
"element": {
"name": "pd6",
"children": {}
},
"element": {
"name": "pd5",
"children": {
"element": {
"name": "pd7",
"children": {
"element": {
"name": "pd8",
"children": {}
}
}
}
}
}
}
},
"element": {
"name": "pd4",
"children": {}
}
}
}
}
}
but it only print two objects multiple times
here is my code
function parseConfig(configs){
for(var element in configs){
if (typeof(configs[element])=="object") {
console.log(configs[element]);
parseConfig(configs[element]);
}
}
}
and here is the code on jsfiddle
elementis duplicated many times...