Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Update #matched #key #values #JavaScript #objects
ADD COMMENT
Topic
Name
6+3 =