Created
December 8, 2015 15:21
-
-
Save a-r-d/fb033b01b31d5246e82c to your computer and use it in GitHub Desktop.
Deduplicate an array of objects in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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