Deep clone a value

Javascript

structuredClone handles Dates, Maps, Sets and cycles, which JSON round-tripping quietly destroys.

const copy = structuredClone(original);

// What JSON.parse(JSON.stringify(x)) loses:
//   Date      -> string
//   undefined -> dropped
//   Map, Set  -> {}
//   cycles    -> throws

More in JavaScript

Random picks