SOURCE

// const a = [1,2,3,4,5]
// const b = [1,2,3,5,4]
const a = {a: 19, b: 'zhang'}
const b = {a: 19, b: 'zhang'}
console.log('obj:' , a === b)
function isObject(obj) {
  return Object.prototype.toString.call(obj) === '[object Object]'
}
function isArray(obj) {
  return Object.prototype.toString.call(obj) === '[object Array]'
}

function equalsObj(oldData, newData) {
  if (oldData === newData) return true
  if (isObject(oldData) && isObject(newData) && Object.keys(oldData).length === Object.keys(newData).length) {

    for (const key in oldData) {
      if (oldData.hasOwnProperty(key)) {
        if (!equalsObj(oldData[key], newData[key]))
          //      对象中具有不相同属性 返回false
          return false
      }
    }
  } else if (isArray(oldData) && isArray(oldData) && oldData.length === newData.length) {
    for (let i = 0, length = oldData.length; i < length; i++) {
      if (!equalsObj(oldData[i], newData[i]))
        return false
    }
  } else {
    return false
  }

  return true
}
console.log(equalsObj(a,b))
console 命令行工具 X clear

                    
>
console