Use the build in function structuredClone()
to copy all kind of complex JS types.
Official documentation: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types
Comparison to other copy techniques like spread or json.stringify: https://www.builder.io/blog/structured-clone