userimage

how to add a new key value pair in an existing json object using javascript

I have two json variable as below:


var abc = {'key':"value",'key1':"value",'key2':"value"};
var xyz = {'key3':"value",'key4':"value",'key5':"value"};


And i want to merge abc variable to xyz variable as below output.


{'key3':"value",'key4':"value",'key5':"value","newkey"{'key':"value",'key1':"value",'key2':"value"}}


How to to do this using javascript code.

userimage

try below code to get the result:


var nkey = 'newkey';
xyz[nkey] = abc;
alert(JSON.stringify(xyz));
Answer is