const feature = [
{
attributes: {
data: {
rootType: { type: "string", value: "Alpha" },
rootAge: { type: "integer", value: "10" },
baySize: { type: "integer", value: "18" },
totalBays: { type: "integer", value: "13" }
}
}
},
{
attributes: {
data: {
rootType: { type: "string", value: "Brown" },
rootAge: { type: "integer", value: "20" },
baySize: { type: "integer", value: "180" },
totalBays: { type: "integer", value: "30" }
}
}
},
{
attributes: {
data: {
rootType: { type: "string", value: "Alpha" },
rootAge: { type: "integer", value: "50" },
baySize: { type: "integer", value: "80" },
totalBays: { type: "integer", value: "25" }
}
}
}
];
const allData = feature.map((item) => {
const { data } = item.attributes;
return data
});
console.log(allData);
const expectedResult = [
{
rootType: { type: "string", value: "Alpha" },
rootAge: { type: "integer", value: "10" },
baySize: { type: "integer", value: "18" },
totalBays: { type: "integer", value: "13" }
},
{
rootType: { type: "string", value: "Brown" },
rootAge: { type: "integer", value: "20" },
baySize: { type: "integer", value: "180" },
totalBays: { type: "integer", value: "30" }
},
{
rootType: { type: "string", value: "Alpha" },
rootAge: { type: "integer", value: "50" },
baySize: { type: "integer", value: "80" },
totalBays: { type: "integer", value: "25" }
}
]
console.log(expectedResult)
I have array of object which I get from API.
I need a way to add these objects into array as below.
I have tried mapping over the original array and push these objects to new variable but I can only ever get the first one.
what is the best way to achieve the desired result.
looking forward to your response. thanks