I have this one array with multiple arrays in it, containing objects (responses from HTTP requests)
The big array:
datas = [
[
{
data: {
pid: 107,
value: 5
}
status: 200
},
{
data: {
pid: 108,
value: 42
}
}
],
[
{
data: {
pid: 107,
value: 64
}
status: 200
},
{
data: {
pid: 108,
value: 322
}
}
]
]
Ok, so how could I make a new array (or object) grouped by pid and a sum with values assigned to pid? It is not the typical question with a SUM by property inside array of arrays.
What I have tried:
datas.forEach((d,k1) => {
d.forEach((e,k2) => {
total += e.data.value
newArr[k2] = total;
})
})