Skip to content

Instantly share code, notes, and snippets.

@che-wf
Created July 22, 2016 17:39
Show Gist options
  • Save che-wf/f1c616a32ee4d642691792eebdc4257b to your computer and use it in GitHub Desktop.
Save che-wf/f1c616a32ee4d642691792eebdc4257b to your computer and use it in GitHub Desktop.
This is an efficient approach to finding duplicates in an array or eliminating duplicates from an array.
var a = ["a","a","b","c","c"];
var dupes = a.filter((value,index,self)=>{ return (self.indexOf(value) !== index )});
var cleanArray = a.filter((value,index,self)=>{ return (self.indexOf(value) === index )});
console.log(dupes);
console.log(cleanArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment