Home >Web Front-end >JS Tutorial >Detailed explanation of JS examples of comparing whether the values of two Json objects are equal_javascript skills
return true;
};
modeler.compObj=function(obj1,obj2)//Compare two objects for equality, excluding actual attribute calculations
{
if(( obj1&&typeof obj1==="object")&&((obj2&&typeof obj2==="object")))
{ var count1=modeler.propertyLength(obj1);
var count2=modeler.propertyLength( obj2);
if(count1==count2)
{
for(var ob in obj1)
{
if(obj1.hasOwnProperty(ob)&&obj2.hasOwnProperty(ob))
{ [ob],obj2[ob]))
==="string"&&typeof obj2[ob ; }
[ob],obj2[ob]))
🎜> }
}
else
return false;
}
}
else
{
Return false;
}
}
return true;
};
modeler.propertyLength=function(obj)//Get the number of properties on the object, excluding the properties on the object prototype
{
var count =0;
if(obj&&typeof obj==="object") {
for(var ooo in obj) {
if(obj.hasOwnProperty(ooo)) {
count ;
}
}
return count;
}else {
throw new Error("argunment can not be null;");
}
};
Test data:
Copy code
The code is as follows:
var data01=[{value:[{id:'asa',value:'dfs'},{}]}];
var data02=[{value:[{id:'asa',value:'dfs' },{}]}];
try {
var jjj=modeler.compArray(data01,data02);
}catch(e) {
}