function isObjectValueEqual(a, b) {
let a1 = Object.getOwnPropertyNames(a)
let b1 = Object.getOwnPropertyNames(b)
if (a.length != b.length) {
return false
}
for (let i = 0; i < a1.length; i++) {
let an = a1[i]
let a1n = a[an]
let b1n = b[an]
if (typeof a1n === "object") {
if (isObjectValueEqual(a1n, b1n)) {
return true
} else {
return false
}
} else if (a1n !== b1n) {
return false
}
}
return true
}
// 测试用例-1
let obj1 = {
name: "小猪课堂",
age: 26,
sex: "不知道"
}
let obj2 = {
name: "小猪课堂",
age: 26,
sex: "不知"
}
console.log(isObjectValueEqual(obj1, obj2));
06-15
354
11-11
3084