Here is the one liner that compares by id.
let result = arr1.concat( arr2.filter( i2 => !arr1.find( i1 => i1.id == i2.id ) ) );
I have modified elements to show what happens for different objects with the same id. Swap arr1 with arr2 for which array you want to keep your preferred components. There seems to be no simple way to compare objects in JavaScript, you may use JSON.stringify but that depends on elements order. You can try it out at https://playcode.io/new/ :
var arr1=[{id:1,name:'AB'},{id:2,name:'CD'}];
var arr2=[{id:3,name:'EF'},{id:2,name:'GH'}];
let result;
result = arr1.concat( arr2.filter( i2 => !arr1.find( i1 => i1.id == i2.id ) ) );
console.log('RESULT: ' + JSON.stringify(result));
result = arr1.concat(
arr2.filter(
i2 => !arr1.find(
i1 => {
console.log('I1: ' + JSON.stringify(i1) + ' I2: ' + JSON.stringify(i2));
return i1.id == i2.id;}
)
)
);
console.log('RESULT: ' + JSON.stringify(result));
result = arr2.concat(
arr1.filter(
i1 => !arr2.find(
i2 => {
console.log('I1: ' + JSON.stringify(i1) + ' I2: ' + JSON.stringify(i2));
return i1.id == i2.id;}
)
)
);
console.log('RESULT: ' + JSON.stringify(result));