const sum = [ {id: 1, name: 'a'}, {id: 2, name: 'b'}]
const arr1 = [ {id: 1, cat: '1'}, {id: 2, cat: '6'}]
const arr2 = [ {id: 1, s: '2'}, {id: 2, s: '6'}]
const res = [{id: 1, name: 'a', cat: '1', s: '2'}, {id: 2, name: 'b', cat: '6', s: '6'}]
const merge = (key, ...arrs) =>
Object.values(arrs.reduce((acc, arr) => (
arr.forEach(n => Object.assign(acc[n[key]] ??= {}, n)),
acc
), {}));
const result = merge('id', sum, arr1, arr2);
const merge = (key, ...arrs) =>
Array.from(arrs
.flat()
.reduce((acc, n) => {
const k = key(n);
return acc.set(k, Object.assign(acc.get(k) ?? {}, n));
}, new Map)
.values()
);
const result = merge(n => n.id, sum, arr1, arr2);