To get every unique element in an array, you can use the Set()
constructor and the filter()
method together.
index.tsx145 chars6 lines
In the code above, we create a new Set
object from our array
, which only contains unique elements. Then, we convert this Set
back into an array using the Array.from()
method. This gives us an array of only the unique elements.
gistlibby LogSnag