Skip to content

Instantly share code, notes, and snippets.

@pawiromitchel
Created January 27, 2017 11:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawiromitchel/342959e1aa913bf8fcbd81a856d25a2d to your computer and use it in GitHub Desktop.
Save pawiromitchel/342959e1aa913bf8fcbd81a856d25a2d to your computer and use it in GitHub Desktop.
JS - remove duplicates from an array
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