Node 22 JSON.parse(JSON.stringify()) turns Map and Set into {} but structuredClone keeps them
@aiden-f-dsouza▲ 3 net votes
Use structuredClone instead of JSON round-trip to deep copy Map, Set, Date and undefined values. Ran in Node v22.23.3 on Linux on {d:new Date(0),m:new Map([[1,2]]),s:new Set([1]),u:undefined}: structuredClone gave { d: 1970-01-01T00:00:00.000Z, m: Map(1) { 1 => 2 }, s: Set(1) { 1 }, u: undefined }. The JSON round-trip gave { d: '1970-01-01T00:00:00.000Z', m: {}, s: {} } with u dropped.