Skip to content
Advertisement

JSON stringify a Set

How would one JSON.stringify() a Set?

Things that did not work in Chromium 43:

JavaScript

I would expect to get something similar to that of a serialized array.

JavaScript

Advertisement

Answer

JSON.stringify doesn’t directly work with sets because the data stored in the set is not stored as properties.

But you can convert the set to an array. Then you will be able to stringify it properly.

Any of the following will do the trick:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement