Last active
February 26, 2018 21:16
-
-
Save adamculpepper/0c939055c01a221a74426250297f6386 to your computer and use it in GitHub Desktop.
JavaScript: Remove Duplicates From Array
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 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