I have an array of objects that have duplicate unique id's due to a join with another data set. This is due to the limitation of the API returning the data. What I want to do is to find duplicate rows and join the unique column of data in JavaScript. As an example, this is what I have:
var data = [
{id: 1, name: 'Joe', type:'Red'},
{id: 2, name: 'Smith', type:'Red'},
{id: 2, name: 'Smith', type:'Green'},
{id: 3, name: 'Ana', type:'Blue'},
];
this is the result I need:
var data = [
{id: 1, name: 'Joe', type:'Red'},
{id: 2, name: 'Smith', type:'Red, Green'},
{id: 3, name: 'Ana', type:'Blue'},
];
I figured I could create a nested for loop but I believe performance wise it wouldn't be ideal. I tried using the Array.prototype.filter but couldn't achieve what I needed here.