Shallow copy
var newObject = jQuery.extend({}, oldObject);
Deep copy
var newObject = jQuery.extend(true, {}, oldObject);
What is shallow copy and deep copy?
If you need to copy(clone) object a to object b in Javascript using jQuery, do like this.
// old object
var a = {"name":"John Smith", "age":"30"};
// new object, we need to copy the contents of object a to object b
var b = jQuery.extend(true, {}, a);
This is a sample program
// old object
var a = {"name":"John Smith", "age":"30"};
console.log("Printing the contents of object a in Firebug console");
console.log(a);
// new object, we need to copy the contents of object a to object b
var b = jQuery.extend(true, {}, a);
console.log("Printing the contents of object a in Firebug console");
console.log(b);
// Now we are editing the contents of object a
a.name = "Mary Smith";
a.age = "31"
// Print the object again
console.log("Printing the contents of object a in Firebug console");
console.log(a);
console.log("Printing the contents of object b in Firebug console");
console.log(b);
// Note that even though we changed the contents of object a, the contents of object b is not changed.
The output in firebug console will look like this.
Printing the contents of object a in Firebug console
Object { name="John Smith", age="30"}
Printing the contents of object a in Firebug console
Object { name="John Smith", age="30"}
Printing the contents of object a in Firebug console
Object { name="Mary Smith", age="31"}
Printing the contents of object b in Firebug console
Object { name="John Smith", age="30"}
Note that even though we changed the contents of object a, the contents of object b is not changed.
Hope this information is useful to you.