Deep clone an object with jQuery Deep clone an object with jQuery

To copy/clone an object using jQuery, you will want to leverage the extend function. This function accepts N objects to clone/merge as well as a boolean to indicate whether it should copy recursively or not.

Using $.extend to clone an object

In the example below, the jQuery extend function will be used to copy the properties from objectA to objectB. This will be done twice to demonstrate the difference between a recursive clone and non-recursive clone.

After objectA has been copied to objectB, 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.

Published on Feb 19, 2019

Tags: extend | JavaScript | jQuery Tutorial | clone

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.


Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.