javascript remove duplicate objects from array using map code example
Example 1: remove duplicate objects from array javascript
const addresses = [...];
const uniqueAddresses = Array.from(new Set(addresses.map(a => a.id)))
.map(id => {
return addresses.find(a => a.id === id)
})
Example 2: remove duplicates objects from array javascript
function remove_duplicate_objects(data,prop) {
var seen = {};
data = data.filter(function (entry) {
if (seen.hasOwnProperty(entry[prop])) {
return false;
}
seen[entry.prop] = entry;
return true;
});
return data
}
const new_array = remove_duplicate_objects([array with objects inside])