转载
地址:js判断对象是否相等
作者:dengshangli
function equals( x, y ) {
var in1 = x instanceof Object;
var in2 = y instanceof Object;
if(!in1||!in2){
return x===y;
}
if(Object.keys(x).length!==Object.keys(y).length){
return false;
}
for(var p in x){
var a = x[p] instanceof Object;
var b = y[p] instanceof Object;
if(a&&b){
return equals( x[p], y[p]);
}
else if(x[p]!==y[p]){
return false;
}
}
return true;
}
console.log(equals({a:1},{a:1}));//true
来源:CSDN
作者:天空影
链接:https://blog.csdn.net/jx950915/article/details/78568055