[{id: 123}, {id: 456}, {id: 789}]
, и второй:[
{id: 123, title: 'Mercedes'},
{id: 456, title: 'BMW'},
{id: 789, title: 'Land Rover'},
{id: 789346, title: 'Lamba'},
{id: 54534, title: 'Enzo Ferrari'}
]
isAdded: true
. Как это сделать? arr1.forEach(function({ id }) {
if (this[id]) {
this[id].isAdded = true;
}
}, arr2.reduce((acc, n) => (acc[n.id] = n, acc), {}));
const newArr2 = arr2.map(function({ ...n }) {
if (this.has(n.id)) {
n.isAdded = true;
}
return n;
}, new Set(arr1.map(n => n.id)));