📌  相关文章
📜  更新两个 JavaScript 对象中匹配的键值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:33.160000             🧑  作者: Mango

代码示例1
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;
    }