Created
May 5, 2021 17:19
-
-
Save rafaeldcastro/96ce2b580b643c6ecf2a17632c7d2ef7 to your computer and use it in GitHub Desktop.
Remove all duplicates from an Array of objects
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
/* | |
arr = [ {id: 1, name: 'Foo'}, {id: 1, name: 'Foo'}] | |
*/ | |
let noDuplicates = arr.filter((obj_a, index, self) => | |
index === self.findIndex((obj_b) => ( | |
obj_a.attr === obj_b.attr //CHANGE attr for any attribute, like id | |
)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment