Given a json like this
var json1 = {
"key1": {
"index": "1",
"value": null
},
"key2": {
"index": "2",
"value": null
},
"key3": {
"index": "3",
"value": null
};
var json2 = {
"key3": {
"index": "3",
"value": "value3"
},
"key4": {
"index": "4",
"value": 'value4'
}
};
how to get a new json like this, it will only copy the same key to the first one.
json3= {
"key1": {
"index": "1",
"value": null
},
"key2": {
"index": "2",
"value": null
},
"key3": {
"index": "3",
"value": 'value3'
}
};
I've tried on Object.assign
or _.assign
of lodash
Object.assign(json1,json2)
_.assign(json1,json2)
but it will copy all the objects of json2 to json1.