DEV Community

Discussion on: 15 Killer πŸ—‘ JS techniques you've probably never heard of πŸ”ˆπŸ”₯

Collapse
 
nielsabildgaard profile image
Niels Abildgaard • Edited

🚩 Red flag! I wouldn't trust the above code for general use.

Your Unique Array of Objects solution uses the incredibly expensive JSON.stringify and JSON.parse to do object comparison. While the code looks neat it is probably the least efficient way to go about it.

A better approach would use _.isEqual for deep comparisons, or a concrete comparison on the significant fields, if not all fields are significant (which they rarely are --- e.g. an id field may imply the state of the other fields).

As others have pointed out, your solution is not even correct.


I found this post via the "Top" posts page, which seems to be because it is getting a lot of engangement. I can't help but wonder whether your bad advice is intentional---to get engangement. You've gotten lots of feedback, but made no adjustments to the post.


The only thing these tips will kill is your app performance.