Despite the less-than-desirable name of this inquiry, the question is fairly straightforward. I have a particular object:
let test = {
date1: [
{
time: 1,
value: 5,
},
{
time: 2,
value: 6,
},
],
date2: [
{
time: 1,
value: 20,
},
{
time: 2,
value: 10,
},
],
};
I am looking to reformat it into something like this:
let result = {
date1: {
values: [5, 6],
times: [1, 2],
},
date2: {
values: [1, 2], // perhaps easier for summarization?!
times: [10, 20],
},
};
I am aiming to summarize the value
data for each date. The idea is that having them in an array will simplify the summarization process. While aware of alternative methods (and open to exploring them), my current approach is falling short of my expectations. Here's what I have at the moment:
let keys = Object.keys(test);
let red = keys.reduce((acc, curr) => {
return (acc[curr] = test[curr].map((e) => e.value));
}, {});
console.log(`red: `, red);
However, its output is as follows:
red: [ 20, 10 ]