Skip to content

Instantly share code, notes, and snippets.

@martinratinaud
Last active May 10, 2021 10:48
Show Gist options
  • Save martinratinaud/d522343274c93ed334392f1a630a726f to your computer and use it in GitHub Desktop.
Save martinratinaud/d522343274c93ed334392f1a630a726f to your computer and use it in GitHub Desktop.
Filter duplicates in array of objects - one line
const uniqueBy = (items: any[]) => (key: string) =>
[...new Map(items.map(item => [item[key], item])).values()]
// OR
const unique = [...new Map(items.map(item => [item[key], item])).values()];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment