Created
September 18, 2019 19:06
-
-
Save mikemcbride/92433d8c5fe487ad2491ed5c8fd50118 to your computer and use it in GitHub Desktop.
Get unique values from an array in JS
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
function uniq(arr) { | |
let result = [] | |
let seen = new Set() | |
for (let val of arr) { | |
if (!seen.has(val)) { | |
seen.add(val) | |
result.push(val) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment