oldObj is an object, not a value
For example, var newObj=oldObj;
If you want oldObj to change without affecting newObj;
You can write a function like this
function clone(myObj){
if(typeof(myObj) != 'object') return myObj ;
if(myObj == null) return myObj;
var myNewObj = new Object();
for(var i in myObj)
myNewObj[i] = clone(myObj[i]) ;
return myNewObj;
}
Then call
newObj=clone(oldObj)
After that, no matter how the value of oldObj changes, it will not affect newObj
JavaScript copy object
Syntax:
oElement = object . cloneNode ( bCloneChildren )
Parameters:
bCloneChildren: Optional. Boolean. false | true
false : Default value. When cloning an object, it does not include the object's childNodes collection. That is, all its child objects.
true : Include object’s childNodes collection when cloning object. That is, all its child objects.
Return value:
oElement : Object (Element). Returns a reference to the new cloned object.
Description:
Clone object in the document structure.
After cloning, when getting the id of the cloned object, a collection will be returned.
It is OK to use this method at runtime. The document space may not be rendered until the object's closing tag is parsed.
Sample code: