i have a problem, with my code basically i'm trying to merge the duplicate objects and add the additional property 'admin' set to 'true' and for unique objects additional property 'admin' set to 'false'
const addresses = [{name: 'Paul', id: 2}, {name: 'John', id: 1}, {name: 'John', id: 1}];
//combine duplicate object and add property admin: true
let result = [];
addresses.forEach(elem => {
let match = result.find(r => r.id === elem.id);
if(match) {
return {...match, ...elem, admin: true};
} else {
result.push({...elem, admin: false });
}
});
but im doing this incorrectly as the output i get is
const addresses = [{name: 'Paul', id: 2}, {name: 'John', id: 1}, {name: 'John', id: 1}];