Copy codeThe Code is as follows:
// Compare whether the array is the same
Modeler. compArray = function (array1, array2)
{
If (array1 & typeof array1 = "object" & array1.constructor = Array) & (array2 & typeof array2 = "object" & array2.constructor = Array ))
{
If (array1.length = array2.length)
{
For (var I = 0; I <array1.length; I ++)
{
Var ggg = modeler. compObj (array1 [I], array2 [I]);
If (! Ggg)
{
Return false;
}
}
}
Else
{
Return false;
}
}
Else
{
Throw new Error ("argunment is error ;");
}
Return true;
};
Modeler. compObj = function (obj1, obj2) // compare whether two objects are equal and do not contain original attributes.
{
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 ))
{
If (obj1 [ob]. constructor = Array & obj2 [ob]. constructor = Array) // if the attribute is an Array
{
If (! Modeler. compArray (obj1 [ob], obj2 [ob])
{
Return false;
};
}
Else if (typeof obj1 [ob] === "string" & typeof obj2 [ob] === "string") // pure attribute
{
If (obj1 [ob]! = Obj2 [ob])
{
Return false;
}
}
Else if (typeof obj1 [ob] === "object" & typeof obj2 [ob] === "object") // The attribute is an object
{
If (! Modeler. compObj (obj1 [ob], obj2 [ob])
{
Return false;
};
}
Else
{
Return false;
}
}
Else
{
Return false;
}
}
}
Else
{
Return false;
}
}
Return true;
};
Modeler. propertyLength = function (obj) // obtain the number of attributes on the object, excluding attributes on the original object.
{
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 codeThe 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 ){
}