I want to code an object name with a dynamic string variable.
this.datas: [
{
name: "john",
data: 10
}
{
name: "add",
data: 20
}
]
this.latestBarChart: {
chartName: "Line",
style: "red"
}
for (let i = 0; i < this.datas.length; i++) {
this.screenData[i].data.push(JSON.parse(`${this.datas[i].name}`: this.latestBarChart));
}
I tried like this. But there is an error because of this : while I push
this.screenData[i].data.push(JSON.parse(`${this.datas[i].name}`: this.latestBarChart));
How can I do this ?
JSON.parse? There is no JSON there. And what is your expected result? Did you check the documentation ofpush?JSON.parse, there is still same error