Answers for "js array filter duplicate object"

-1

remove duplicate object from array javascript

let uniqIds = {}, source = [{id:'a'},{id:'b'},{id:'c'},{id:'b'},{id:'a'},{id:'d'}];
let filtered = source.filter(obj => !uniqIds[obj.id] && (uniqIds[obj.id] = true));
console.log(filtered);
// EXPECTED: [{id:'a'},{id:'b'},{id:'c'},{id:'d'}];
Posted by: Guest on August-04-2021

Code answers related to "js array filter duplicate object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language