Here's how it's done in its simplest form:
How does this work? To put it simply, each item in a set must be unique. By spreading the Set into an array, you create a new array with only those unique items.
Some caveats: In this simple form, it will not work with nested arrays or arrays of objects, since they are only duplicates in appearance -- Behind the scenes, they're new copies and thus will not be purged out by using this method. You can get creative to figure out how to do this (reduce would work here!), however it's always better to handle this on the back end!
Top comments (0)