Convert a set into a string

Darren Jones
May 6, 2021

The built-in `toString()` method for sets will just display “[object Set]”, which isn’t very useful. The following code will return a string containing the values of the set, separated by commas:

copy code
javascript
[...set].join()

This uses the spread operator to convert the set into an array first, then the `Array.join()` method to convert it into a string of comma-separated values.

Know a better answer? Join our our community and let us know.