I am working with a REST API that delivers data in JSON format. I have stored this data in an array of objects, but now I want to add a new empty array to each object which is proving to be challenging. Below is a snippet of how my REST API data is structured, and I have indicated where I would like to insert the new array 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[]
}
}]
This is what I have attempted so far.
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);
});