Which approach correctly creates a deep copy of a plain JSON-serializable object in modern JavaScript?

JavaScript Developer Medium

JavaScript Developer — Medium

Which approach correctly creates a deep copy of a plain JSON-serializable object in modern JavaScript?

Key points

  • structuredClone(obj) creates a deep copy of the object
  • Object.assign({}, obj) creates a shallow copy
  • { ...obj } creates a shallow copy as well
  • Object.create(obj) is used for prototypal inheritance

Ready to go further?

Related questions