You could make a "clone" function that creates a new object, based on the original object constructor, and then clone that original object properties also if they are objects:
function clone(obj){ if(typeof(obj) != 'object' && obj != null) return obj; // return the value itself if isn't an object // or null, since typeof null == 'object'; var temp = new obj.constructor(); for(var key in obj) temp[key] = clone(obj[key]); return temp; } var a = {'foo': []}; var b = clone(a); a['foo'].push(1); console.log(b); // Object foo=[0]
console.logfunction to work.