Skip to content

Instantly share code, notes, and snippets.

@a-r-d
Created December 8, 2015 15:21
Show Gist options
  • Save a-r-d/fb033b01b31d5246e82c to your computer and use it in GitHub Desktop.
Save a-r-d/fb033b01b31d5246e82c to your computer and use it in GitHub Desktop.
Deduplicate an array of objects in javascript
function deDupeArrayOfObjects(arr) {
var tmpMap = {};
arr.forEach(function(val) {
var uniquekey = '';
for(var k in val) {
if(val.hasOwnProperty(k) && val[k]) {
uniquekey += val[k].toString();
}
}
tmpMap[uniquekey] = val;
});
var deDuped = [];
for(var key in tmpMap) {
deDuped.push(tmpMap[key]);
}
return deDuped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment