Currently facing an issue while trying to assign values from a JSON response to another variable. The error message "Cannot set property name of undefined" is appearing.
export interface Data
{
description: any;
name : any;
}
Within the main class, I have defined the following data
actionData : any;
action:Data[]=[];
getData()
{
this.spref.getNewData().subscribe(
response => {
this.actionData = response;
for(let i=0;i<this.actionData.length;i++)
{
this.action[i].name = this.actionData[i].name;
this.action[i].description = this.actionData[i].description;
}
})
},
error => {
console.log('Failure: ', error);
}
);
}
The format of the actionData response is as follows:
[{
description: "pqrs"
jsonType: "com.xyz.common.object.NewData"
name: "abc"
value: "xyz"
}]
The desired format for storing the action data is:
[{
description: "pqrs"
name: "abc"
}]
Thank you in advance!