Skip to content

Instantly share code, notes, and snippets.

@hmtri1011
Last active July 2, 2020 15:31
Show Gist options
  • Save hmtri1011/4d5c1881d1d90c9ba7af3428b1a3055e to your computer and use it in GitHub Desktop.
Save hmtri1011/4d5c1881d1d90c9ba7af3428b1a3055e to your computer and use it in GitHub Desktop.
Unique by without lodash
const uniqBy = (array, key) => {
const mapKey = array.reduce((prev, cur) => {
const keyValue = key ? cur[key] : cur
return {
...prev,
[keyValue]: cur
}
}, {})
return Object.values(mapKey)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment