I have an array of objects like this:
[
{
name: "test",
type: ['R'],
},
{
name: "test2",
type: ['D'],
},
{
name: "test",
type: ['B'],
},
{
name: "test3",
type: ['R'],
},
{
name: "test2",
type: ['A'],
},
]
and I want to remove duplicates and update the type with all validated types to be like this:
[
{
name: "test",
type: ['R', 'B'],
},
{
name: "test2",
type: ['D', 'A'],
},
{
name: "test3",
type: ['R'],
},
]
I try to use the filter function and it removes duplicates but on the update is a duplicate of the same type
array.filter((o,i,os)=>(os.findIndex(v2=>(v2.name===o.name && ( o.type = o.name.concat(v2.type) ) )))===i)
is there any solution?