Created
September 6, 2019 18:30
-
-
Save masautt/f1deaa07515d9cdfc1a306c8f99d1e21 to your computer and use it in GitHub Desktop.
How to check if all elements in an array are unique in JavaScript?
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
function hasDuplicates(array) { | |
return (new Set(array)).size !== array.length; | |
} | |
console.log(hasDuplicates(["M", "A", "S", "A", "U", "T", "T"])); // --> true | |
console.log(hasDuplicates(["M", "A", "R", "E", "K"])); // --> false | |
// https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment