Created
January 27, 2017 11:26
-
-
Save pawiromitchel/342959e1aa913bf8fcbd81a856d25a2d to your computer and use it in GitHub Desktop.
JS - remove duplicates from an array
This file contains 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 removeDuplicates(originalArray, prop) { | |
var newArray = []; | |
var lookupObject = {}; | |
for(var i in originalArray) { | |
lookupObject[originalArray[i][prop]] = originalArray[i]; | |
} | |
for(i in lookupObject) { | |
newArray.push(lookupObject[i]); | |
} | |
return newArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment