Created
April 3, 2017 02:00
-
-
Save manovotny/a6b1188ac605b1f5c5fb4be24d798fc4 to your computer and use it in GitHub Desktop.
Dedupe 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
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