Remove duplicates from an array of objects in JavaScript

Nice and clean if you only want to remove objects with a single duplicate value, not so clean for fully duplicated objects.

export const uniqueArray = arr => {
return Object.values(
arr.reduce((acc, cur) => Object.assign(acc, { [cur.id]: cur }), {}),
);
};

https://stackoverflow.com/questions/2218999/remove-duplicates-from-an-array-of-objects-in-javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.