I have an object of arrays
{Cost One: Array(1), Cost Two: Array(1), Cost Five: Array(1)}
Cost One: Array(1)
0: "22"
length: 1
Cost Two: Array(1)
0: "33"
length: 1
Cost Five: Array(1)
0: "1456"
length: 1
Desired output :
[{Cost One: "22"}, {Cost Two: "33"}, {Cost Five: "1456"}]
My code to convert :
const mappedDataArray = [];
for (const key in costsFormValues) {
const mappedData = {
...costsFormValues[key]
};
mappedDataArray.push(mappedData);
}
Output :
[{…}, {…}, {…}]
0: {0: "22"}
1: {0: "33"}
2: {0: "1456"}
Here instead of 0, how do i add key name that is Cost One and so on
What am i making wrong here ?