Skip to content

Instantly share code, notes, and snippets.

@manovotny
Created April 3, 2017 02:00
Show Gist options
  • Save manovotny/a6b1188ac605b1f5c5fb4be24d798fc4 to your computer and use it in GitHub Desktop.
Save manovotny/a6b1188ac605b1f5c5fb4be24d798fc4 to your computer and use it in GitHub Desktop.
Dedupe Array of Objects
var items = [
{
someProp: '0',
otherProp: 'a'
},
{
someProp: '1',
otherProp: 'c'
},
{
someProp: '2',
otherProp: 'b'
},
{
someProp: '1',
otherProp: 'c'
},
{
someProp: '3',
otherProp: 'd'
}
];
var deduped = items.reduce(function(accumulator, item) {
accumulator[item.someProp] = item;
return accumulator;
}, {});
console.log(deduped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment