2017  Kodetalk | Feedback | Privacy Policy | Terms | About

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.


How to to do this using javascript code.


try below code to get the result:

var nkey = 'newkey';
xyz[nkey] = abc;
Answer is