I have a question regarding how to push/replace data into an object of an array of objects. Please excuse any mistakes in my grammar. Here is my dummy data:
const dummyData = {
id: 1,
daerah: "Bandung",
date:"1668790800000",
kendaraan: [
{rodaEmpat: 50},
{rodaDua: 22},
{truck: 30},
{Bus: 70},
]
}, {
id: 2,
daerah: "Tasik",
date:"1668877200000",
kendaraan: [
{rodaEmpat: 80},
{rodaDua: 15},
{truck: 10},
{Bus: 50},
]
},
Here is the variable 'data' that I want to push into:
data: {
datasets: [
{
data: [50, 40, 80, 19],
backgroundColor: ["#6225E3", "#E32525", "#E7A543", "#3EAFE0"],
},
],
},
I want to push/override data.datasets[0].data with values from dummyData.kendaraan (this data needs to be processed using the map function first). The expected result should look like this:
data: {
datasets: [
{
data: [50, 22, 30, 70],
backgroundColor: ["#6225E3", "#E32525", "#E7A543", "#3EAFE0"],
},
],
},
Thank you for your help!