I've a REST API which contains data in JSON format. I'm storing it in an array of objects. But I want to append a NEW EMPTY array to each object. I'm not able to do it. Here is how my REST API looks like. I marked the new array which I want to add for each object in the comments.
content = [
{
text: 'abc',
options: [
{
Id: 1,
Text: 'aaa'
},
{
Id: 2,
Text: 'bbb'
},
{
Id: 3,
Text: 'ccc'
}],
// ARRAY[]
},
{
text: 'def',
options: [
{
Id: 21,
Text: 'qwerty'
},
{
Id: 22,
Text: 'zxcv'
},
{
Id: 23,
Text: 'asdf'
}],
// ARRAY[]
}
}]
here is what I've tried.
public newarr:Array<any>;
this.httpservice.post('RESTUrl').subscribe(resp=>{
this.contents = resp.data;
this.contents.forEach((x:any)=>{
x.push(this.newarr);
});
console.log("contents",this.contents);
});