Last active
May 10, 2021 10:48
-
-
Save martinratinaud/d522343274c93ed334392f1a630a726f to your computer and use it in GitHub Desktop.
Filter duplicates in array of objects - one line
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
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