Answers for "Update matched key values in two JavaScript objects"

0

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;
    }
Posted by: Guest on June-04-2020

Code answers related to "Update matched key values in two JavaScript objects"

Code answers related to "Javascript"

Browse Popular Code Answers by Language