Deep clone an object with JavaScript

JSON.parse

JSON.stringify

extend

Using JSON.parse and JSON.stringify to clone

JSON.parse

JSON.stringify

To copy/clone an object using JavaScript, you will want to leverage thefunction in combination with thefunction.If you are looking for a jQuery solution, you will want to leverage thefunction which can be found in the Deep clone an object with jQuery article.In the following example two objects will be created: objectA and objectB. objectA will be used as the existing object that will be copied/cloned into objectB.Once objectA has been cloned to objectB using thefunction in combination with thefunction, the output of the copy is outputted on screen and shows that the full object, including child properties, have been copied to the new object.