Skip to content

Instantly share code, notes, and snippets.

@roshanca
Last active June 22, 2018 08:30
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save roshanca/9099d784a0727aae1228142f340b6475 to your computer and use it in GitHub Desktop.
unique array
const arr = ['aaa', 'bbb', 'aaa', '111'];
const uniqueArr = arr.filter((item, index) => {
return arr.indexOf(item) === index;
});
console.log(uniqueArr); // ['aaa', 'bbb', '111']
const simpleUnique = function(arr) {
return [...new Set(arr)]
}
console.log(simpleUnique(arr)); // ["aaa", "bbb", "111"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment