Cloning a JavaScript object with jQuery

Today I heard from John Resig on StackOverflow about how to clone objects using jQuery:

// Shallow copy
var newObject = jQuery.extend({}, oldObject);

// Deep copy
var newObject = jQuery.extend(true, {}, oldObject);

Leave a Reply