Deep clone

Published: July 20, 2022

Sometimes you want to clone an object but make sure that properties don't reference anything in the old object, which could happen with using the spread operator. You can instead use the built-in method structuredClone().

const thing = {
  list: [1, 2, 3],
const clone = structuredClone(thing)

No need for JSON.parse(JSON.stringify(thing))