Skip to content

Instantly share code, notes, and snippets.

@renesansz
Created January 23, 2015 07:47
Show Gist options
  • Save renesansz/fd4363a0a29d0efbc2c9 to your computer and use it in GitHub Desktop.
Save renesansz/fd4363a0a29d0efbc2c9 to your computer and use it in GitHub Desktop.
Remove duplicates in Javascript Array
(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