I have an array as mentioned below:
var somevalue = [{
code: 1,
name: 'a1'
}, {
code: 2,
name: 'b1'
}, {
code: 1,
name: 'a2'
},
{
code: 1,
name: 'a3'
},
{
code: 2,
name: 'b2'
}
]
From this array, I want to find duplicate element by code and merge all elements of the same code into one. So the final output would be:
var somevalue = [{
code: 1,
name: 'a1, a2'
}, {
code: 2,
name: 'b1, b2, b3'
}
]
is there any way to achieve this using underscoreJS ?
I can do this by for-loop. But In real scenario, its very large array containing JSON object of having 10 properties. So I need some performance oriented solution.