Created
January 11, 2019 09:04
-
-
Save 6ui11em/df8f534009db767b93c2d58977a80c3a to your computer and use it in GitHub Desktop.
Javascript remove array duplicates #javascript #js #array #duplicates
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
var sandwiches = ['turkey', 'ham', 'turkey', 'tuna', 'pb&j', 'ham', 'turkey', 'tuna']; | |
var deduped = sandwiches.filter(function (sandwich, index) { | |
return sandwiches.indexOf(sandwich) === index; | |
}); | |
// Logs ["turkey", "ham", "tuna", "pb&j"] | |
console.log(deduped); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment