I have an array of objects in angularjs
var list = [{id: 'foo' , value:'bar1'},
{id: 'foo1' , value:'bar1'}];
I want to add a child object for the first id that equals 'foo'
Formatted JSON Data:
[
{
"id":'foo',
"value":'bar1',
"children":{
id:'foo',
value:'baar'
}
},
{
"id":'foo1',
"value":'bar1'
}
];
I have tried
var tempList = {id:'foo', value:'baar'};
if(list.id =='foo' )
list.id.children = tempList ;
But its not inserting the value