Skip to content

Instantly share code, notes, and snippets.

@antoniocsoares
Last active April 6, 2017 15:23
Show Gist options
  • Save antoniocsoares/3566518c50b855bb7cdb48895dfcd468 to your computer and use it in GitHub Desktop.
Save antoniocsoares/3566518c50b855bb7cdb48895dfcd468 to your computer and use it in GitHub Desktop.
Create Array with unique values
// 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