I'm currently struggling with a task, hope somebody can guide me in the right direction.
I have this array:
const data = [
{
year: 2021,
data: [
{ month: 'Jan', amount: 5000000 },
{ month: 'Feb', amount: 3500000 },
{ month: 'Mar', amount: 15000000 },
{ month: 'Apr', amount: 5000000},
{ month: 'May', amount: 3500000 },
{ month: 'Jun', amount: 15000000 },
{ month: 'Jul', amount: 13000000 },
{ month: 'Aug', amount: 20000000 }
]
},
{
year: 2020,
data: [
{ month: 'Jan', amount: 5000000 },
{ month: 'Feb', amount: 3500000 },
{ month: 'Mar', amount: 15000000 },
{ month: 'Apr', amount: 5000000},
{ month: 'May', amount: 3500000 },
{ month: 'Jun', amount: 15000000 },
{ month: 'Jul', amount: 13000000 },
{ month: 'Aug', amount: 20000000 }
]
}
]
And I'm trying to clean this so I can use HighCharts JS, which needs the following structure:
const data = [
{ year: '2021',
data: [5000000, 3500000, 15000000, 5000000, 3500000, 15000000, 13000000, 20000000 ]
},
{ year: '2020',
data: [5000000, 3500000, 15000000, 5000000, 3500000, 15000000, 13000000, 20000000 ]
}
]
So basically, is to clean the data array inside each object to get only the amount value without the month name. I tried doing a map and storage the result in a useState (I'm working with React JS) with no success.
Any idea would be highly appreciated.