Last active
June 22, 2018 08:30
-
-
Save roshanca/9099d784a0727aae1228142f340b6475 to your computer and use it in GitHub Desktop.
unique array
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
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