set value multiple key object javascript code example
Example: Update matched key values in two JavaScript objects
var obj1={"id" : 1, "name" : "java"},
obj2={"id" : 1, "name" : "java4you", "gender" : "male"};
function compare(obj1, obj2) {
let obj = {};
for(let k in obj1) {
if(obj1[k] !== obj2[k]) {
obj = Object.assign({}, obj1, obj1[k] = obj2[k]);
}
}
return obj;
}