Oldobject = {'name':'Joe','age':12};
newObject = {'address':'XXX'};
I want to get result like :
{'name':'Joe','age':12,'address':'XXX' }
I use
Oldobject.address = newObject
Is there any graceful way to do this ?
Oldobject = {'name':'Joe','age':12};
newObject = {'address':'XXX'};
I want to get result like :
{'name':'Joe','age':12,'address':'XXX' }
I use
Oldobject.address = newObject
Is there any graceful way to do this ?
for (var property in Oldobject) {
newObject[property] = Oldobject[property];
}
Use a for... in
loop, like:
for( var property in newObject ){
OldObject[property] = newObject[property]
}
This will put all of the stuff from newObject
into oldObject
.