Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Last active July 11, 2017 09:01
Show Gist options
  • Save SergProduction/3935b07a57b7b145d00aa13b39e06610 to your computer and use it in GitHub Desktop.
Save SergProduction/3935b07a57b7b145d00aa13b39e06610 to your computer and use it in GitHub Desktop.
const arr = [
{ val: 'A' },
{ val: 'B' },
{ val: 'C' },
{ val: 'B' },
{ val: 'D' },
{ val: 'C' },
{ val: 'B' },
{ val: 'D' },
{ val: 'C' },
{ val: 'B' },
{ val: 'D' },
{ val: 'C' },
{ val: 'X' },
{ val: 'A' },
];
const filtered = arr.reduce((acc, arrItem) => {
acc[arrItem.val] = arrItem
return acc
}, {})
const res = Object.values(filtered)
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment