loading...

re: Remove Duplicates The Shortest Way VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Just to note that Set values are compared by reference for uniqueness - this can catch you out if your Array contains objects rather than primitive...
 

Great advice! But how can we consider objects as duplicates even if they have same properties when they are passed by reference. So I think objects case is not applicable to this problem.

 

If you considered these objects duplicates [{id:1}, {id:1}], the Set approach won't suit. In this case though you'd probably need to use a utility library like Lodash: _.uniqWith(objects, _.isEqual)

Code of Conduct Report abuse