I'm trying to manipulate this object so it matches the corresponding count to its id
.
const data= [
[
{id: "333", count: 555},
{id: "2", count: 133},
{id: "444", count: 13},
{id: "433", count: 32},
{id: "3333", count: 2}
],
[
{id: "333", count: 5565},
{id: "2", count: 1633},
{id: "444", count: 136},
{id: "433", count: 362},
{id: "3333", count: 62}
],
[
{id: "333", count: 585},
{id: "2", count: 1383},
{id: "444", count: 138},
{id: "433", count: 328},
{id: "3333", count: 82}
],
]
To this:
const newData = [
{ id: "333", count: [555, 5565, 585] },
{ id: "2", count: [133, 1633, 1383] },
{ id: "444", count: [13, 136, 138] },
{ id: "433", count: [32, 362, 328] },
{ id: "3333", count: [2, 62, 82] }
]
Something I tried was this, but this just gave me an array with each count seperate.
let ob = test.reduce( ( acc, e, i) => {
let obj = {}
e.forEach((value, index) => {
obj[value.recommendationItemIdExternal] = [value.recommendationItemRating];
})
acc.push(obj);
return acc
}, [] );