bekacodechn
4/3/2020 - 2:48 PM

对象深度比较属性 #比较

对象深度比较属性 #比较

function funDifference(object, other) {
  let diff = {};
  let vChildren;
  for (var key in object) {
      if (typeof object[key] === "object" && typeof other[key] === "object" && object[key] && other[key]) {
          vChildren = funDifference(object[key], other[key]);
          if (Object.keys(vChildren).length > 0) {
              diff[key] = vChildren;
          }


      } else if (object[key] && !other[key]) {
          diff[key] = object[key];

      }
  }
  return diff;
}