How can you create a deep copy of an object in JavaScript?

  • JSON.parse(JSON.stringify(object))
  • object.copy()
  • deepCopy(object)
  • Object.clone(object)
To create a deep copy of an object in JavaScript, you can use JSON.parse(JSON.stringify(object)). This method serializes the object to a JSON string and then parses it back into a new object, effectively creating a deep copy. The other options are not valid for deep copying objects.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *