Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafaeldcastro/96ce2b580b643c6ecf2a17632c7d2ef7 to your computer and use it in GitHub Desktop.
Save rafaeldcastro/96ce2b580b643c6ecf2a17632c7d2ef7 to your computer and use it in GitHub Desktop.
Remove all duplicates from an Array of objects
/*
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