9504 shaares
222 private links
222 private links
Problems with deepcloning with JSON.stringify() / JSON.parse()
:
- Recursive data structures: JSON.stringify() will throw when you give it a recursive data structure. This can happen quite easily when working with linked lists or trees.
- Built-in types: JSON.stringify() will throw if the value contains other JS built-ins like Map, Set, Date, RegExp or ArrayBuffer.
- Functions: JSON.stringify() will quietly discard functions.
The solution: the function structuredClone
.