/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function deepCopy(obj) { if (Object.prototype.toString.call(obj) === '[object Array]') { var out = [], i = 0, len = obj.length; for ( ; i < len; i++ ) { out[i] = arguments.callee(obj[i]); } return out; } if (typeof obj === 'object') { var out = {}, i; for ( i in obj ) { out[i] = arguments.callee(obj[i]); } return out; } return obj; }
URL: http://james.padolsey.com/javascript/deep-copying-of-objects-and-arrays/