Using react I'm looking for a way to transform this Json
[
{
"date":"2019-01-01",
"a":4000,
"f":251,
"h":0.15,
},
{
"date":"2019-01-02",
"a":878,
"f":987,
"h":0.87,
},
{
"date":"2019-01-03",
"a":1287,
"f":412,
"h":0.56,
}
]
Into something like this :
{
date: [
'2019-01-01',
'2019-01-02',
'2019-01-03'
],
a: [
4000,
878,
1287
]
};
But using Array.forEach, It doesn't works because I can't create named keys.
So far here's what I have (tempData is the Json I receive):
let newData = [];
tempData.forEach((element,i) => {
newData['date'][i] = element.date;
newData['a'][i] = element.i;
});
I can't figure out how to make a new array like I want