Is there a way to combine elements from two arrays while avoiding duplicates?
array = [
{id: 1, name:'abc'},{id: 1, name:'xyz'},{id: 2, name:'text1'},{id: 2, name:'text2'}
];
The desired output is:
result = [{id: 1, name:'abc OR xyz'},{id: 2, name:'text1 OR text2'}];
If the ids are the same, the name strings should be concatenated with 'OR'. How can this be achieved using Angular or JavaScript functions? Can it be done using the array.reduce() function? If so, how would that look like? Or do I have to resort to using a for loop?