Skip to content

Instantly share code, notes, and snippets.

@adamculpepper
Last active February 26, 2018 21:16
Show Gist options
  • Save adamculpepper/0c939055c01a221a74426250297f6386 to your computer and use it in GitHub Desktop.
Save adamculpepper/0c939055c01a221a74426250297f6386 to your computer and use it in GitHub Desktop.
JavaScript: Remove Duplicates From Array
var array = ['1', '1', '1', '2', '2', '3', '4', '4', '5', '5', '5'];
function removeDuplicatesFromArray(input) {
var output = input.filter(function(elem, pos, arr) {
return arr.indexOf(elem) == pos;
});
return output;
}
$("#output").text(removeDuplicatesFromArray(array)); // outputs: 1,2,3,4,5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment