As I work on my project to create a table using basic HTML (JSX), I am faced with the challenge of displaying unique dates along with the quantity of apples, strawberries, bananas, and oranges sold each day.
The data obtained from the API is causing difficulties in structuring the table as needed, so I am looking to reorganize it.
const data = [
{
id: 1,
date_sold: "2020-11-14",
fruit: "Apples",
amount: 9,
},
{
id: 2,
date_sold: "2020-11-14",
fruit: "Strawberries",
amount: 2,
},
// more data...
];
The objective is to transform the data into a format like this:
const newData = {
"2020-11-14": { Bananas: 0, Apples: 9, Strawberries: 2, Oranges: 0 },
"2020-11-13": { Bananas: 2, Apples: 1, Strawberries: 3, Oranges: 4 },
// more transformed data...
};