Created
January 23, 2015 07:47
-
-
Save renesansz/fd4363a0a29d0efbc2c9 to your computer and use it in GitHub Desktop.
Remove duplicates in Javascript 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() { | |
var duplicatesArray = ['stop', 'pause', 'resume', 'stop']; | |
// Filter function returns a new array | |
var uniqueArray = duplicatesArray.filter(function(ele, pos) { | |
return duplicatesArray.indexOf(ele) === pos; | |
}); | |
// Expected Output: ['stop', 'pause', 'resume'] | |
console.log(uniqueArray); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment