Last active
April 6, 2017 15:23
-
-
Save antoniocsoares/3566518c50b855bb7cdb48895dfcd468 to your computer and use it in GitHub Desktop.
Create Array with unique values
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
// usage example: | |
const myArray = ['a', 1, 'a', 2, '1']; | |
const unique = myArray.filter((v, i, a) => a.indexOf(v) === i); | |
// unique is ['a', 1, 2, '1'] | |
// usage example: | |
const myArray = ['a', 1, 'a', 2, '1']; | |
const unique = [...new Set(myArray)]; | |
// unique is ['a', 1, 2, '1'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment