Given a list of objects structured like this, I am looking to transform it into a list of values based on their corresponding IDs.
Original = [
{id: 1, value: 12.2494, time: "00:00:00.14"},
{id: 1, value: 4.5141, time: "00:00:01.138"},
{id: 1, value: 2.85930, time: "00:00:02.138"},
{id: 1, value: 1.0364, time: "00:00:03.146"},
{id: 2, value: 4.3510, time: "00:09:15.157"},
{id: 2, value: 3.90, time: "00:09:16.115"},
{id: 2, value: 3.544, time: "00:09:17.116"},
{id: 2, value: 3.247, time: "00:09:18.157"}
]
Desired outcome
data[1]={value:[12.494, 4.5141...],time: ["00:00:00.14","00:00:01.138"]...}
data[2]={value:[4.3510, 3.90...],time: ["00:09:15.157","00:09:16.115"]...}
In attempting this transformation, I encountered an issue where only one value was being returned:
var data= {};
original.forEach(function(item) {
var id = item.id;
data[id] = {
value:[],
time:[]
}
data[id].value.push(item['value']);
data[id].time.push(item['time']);
})