Timeline for How do you JSON.stringify an ES6 Map?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 24, 2023 at 14:02 | comment | added | Laercio Metzner |
Just for additional information, this is totally ok for Typescript users which are able to make sure that the whole map structure (meaning nested objects as well) have string keys Map<string, otherType>
|
|
Apr 6, 2022 at 12:12 | comment | added | Megajin | @AlokSomani yes, you are right. However if you want to parse a JSON (or the newly created Object) back, it won't work. | |
Apr 6, 2022 at 7:35 | comment | added | Alok Somani |
@Megajin Object.fromEntries() is non-destructive, so you will still have your original Map intact.
|
|
Mar 21, 2022 at 13:53 | comment | added | Megajin |
Careful, this is just good if you want to go one way.Object.fromEntries() as stated in the MDN Docs you can parse a Map to an Object but not back! It will throw a object is not iterable error.
|
|
Jun 23, 2021 at 11:36 | comment | added | Procrastin8 | This one is nice but does require you to target ES2019. | |
Sep 18, 2020 at 5:25 | review | Late answers | |||
Sep 18, 2020 at 5:27 | |||||
Sep 18, 2020 at 5:12 | review | First posts | |||
Sep 18, 2020 at 6:21 | |||||
Sep 18, 2020 at 5:09 | history | answered | Alok Somani | CC BY-SA 4.0 |