I am looking some data to create a list of objects, i want to add some of the objects inside the parent object. Although the inner object gets created none of the properties get created with it…
This is what im trying to do:
for(var i in data){
if(parseInt(data[i].prevr) == 0){
nodes[data[i].id] = new Object();
nodes[data[i].id].name = data[i].name;
nodes[data[i].id].child = new Object();
}else if(parseInt(data[i].prevr) > 0){
console.log('test');
nodes[data[i].prevr].child[data[i].id] = new Object();
nodes[data[i].prevr].child[data[i].id].name = data[i].name;
}
}
console.log(JSON.stringify(nodes[5]));
The result shows this in console.log:
test
{"name":"Test2","child":{}}
Why won’t it create the data for the child object?
My variable data holds:
[{"id":"3","name":"Test2","prevr":"0"}
{"id":"4","name":"Test3","prevr":"3"}]
1 Answer