网上找了一圈没一个好用的,只能自己写了。
function isObjEqual (first, seconde) {
const arr1 = Object.keys(first)
const arr2 = Object.keys(seconde)
if (arr1.length != arr2.length) return false
for (const k in first) {
if (typeof first[k] == 'object' || typeof seconde[k] == 'object') {
if (!isObjEqual(first[k], seconde[k])) return false
} else if (first[k] !== seconde[k]) return false
}
return true
}
isObjEqual({a: 123}, {a: 123}) // true
isObjEqual({a: 123, b: 'dss'}, {b: 'dss', a: 123}) // true
isObjEqual({a: 123, b: 'dss', c: [1,2,4]}, {b: 'dss', a: 123, c: [1,2,4]}) // true
isObjEqual({c: [1,2,4], d: {e: 1}}, {c: [1,2,4], d: {e: 1}}) // true