I have two javascript Objects. I want to take a key:Object pair from the first and put it into the second.
var first = { a:1, b:2, c:{c1:11, c2:22, c3:33} }
var second = { d:3, e:4 }
How can I obtain a third object such as this?
{ d:3, e:4, c:{c1:11, c2:22, c3:33} }
Is this the most elegant solution?
var third = second
third.c=first.c
I would like to avoid repeating the .c, something like "take first.c and append both key and value to the second object",
This solution supposes that you have key and value separated: Appending a key value pair to a json object and this one Appending a key value pair to a javascript object adds in fact a new key which does not belong to another object.