Skip to content

Instantly share code, notes, and snippets.

@krohne
Created January 9, 2020 18:00
Show Gist options
  • Save krohne/452456713dd0827d6d1ae10cef8bd2c3 to your computer and use it in GitHub Desktop.
Save krohne/452456713dd0827d6d1ae10cef8bd2c3 to your computer and use it in GitHub Desktop.
Eliminate duplicate array objects
const arr = [
{ id: 1, val: 'a' },
{ id: 2, val: 'b' },
{ id: 1, val: 'a' },
{ id: 1, val: 'c' }
];
const uni = arr
.reduce( ( unique, item ) =>
unique.some( existing =>
item.id === existing.id
&& item.val === existing.val)
? unique
: [...unique, item],
[] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment