Skip to content

Instantly share code, notes, and snippets.

@mikemcbride
Created September 18, 2019 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemcbride/92433d8c5fe487ad2491ed5c8fd50118 to your computer and use it in GitHub Desktop.
Save mikemcbride/92433d8c5fe487ad2491ed5c8fd50118 to your computer and use it in GitHub Desktop.
Get unique values from an array in JS
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