I want to merge 2 array elements to avoid duplicate values
array = [
{id: 1, name:'abc'},{id: 1, name:'xyz'},{id: 2, name:'text1'},{id: 2, name:'text2'}
];
Output should be
result = [{id: 1, name:'abc OR xyz'},{id: 2, name:'text1 OR text2'}];
If ids are the same then name strings should be concatenated with OR. How can i do this using Angular or javascript function? Can i do this using array.reduce() function? if yes how can i do that? Or do i need to use for loop only?