0
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 ?

RedWood
  • 347
  • 1
  • 3
  • 6

2 Answers2

1
for (var property in Oldobject) { 
    newObject[property] = Oldobject[property]; 
}
Kevin Aenmey
  • 13,259
  • 5
  • 46
  • 45
0

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.

willy
  • 1,462
  • 11
  • 12