Browse - Programming Tips - Using jQuery how can I clone an object?

Date: 2017nov17
Language: javaScript
Library: jQuery
Keywords: copy, duplicate

Q.  Using jQuery how can I clone an object?

A.  Use jQuery's extend() like this:

function shallowClone(obj) { return $.extend({}, obj); }
function deepClone(obj) { return $.extend(true, {}, obj); }
function clone(obj) { // A reasonable default return deepClone(obj); }
Example use:
let newObj = clone(oldObj);