📜  比较对象 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:58.727000             🧑  作者: Mango

代码示例1
function isEqual(firstObj, secondObj) {
   const  firstKeys = Object.keys(firstObj);
  const  secondKeys  = Object.keys(secondObj);
  
  if(firstKeys.length !== secondKeys.length){
    return false;
  }
  
  return firstKeys.every(function (key) {
    return firstObj[key] === secondObj[key];
  })
}

const first = {
  property: "value",
  anotherProperty: "another value"
};

const second = {
  property: "value",
  anotherProperty: "another value"
};

const third = {
  property: "value",
  anotherProperty: "yet another value"
};

isEqual(first, second); // true
isEqual(second, third); // false