我写的代码,感觉挺容易理解的,有需要的可以看下
function arraysSimilar(arr1, arr2){
var narr1=new Array();
var narr2=new Array();
if(arr1 instanceof Array==false||arr2 instanceof Array==false){
return false
}
else if(arr1.length==arr2.length){
for(var i=0;i<arr1.length;i++){
narr1[i]=typeof arr1[i];
narr2[i]=typeof arr2[i];
}
for(var i=0;i<arr1.length;i++){
for(var j=0;j<arr2.length;j++){
if(narr1[i]==narr2[j]&&narr1[i]!='object'){
narr1[i]=true;
narr2[j]=true;
break;
}
else if(narr1[i]==narr2[j]&&narr1[i]=='object'){
if(arr1[i]==null||arr2[j]==null){
if(arr1[i]==null&&arr2[j]==null){
narr1[i]=true;
narr2[j]=true;
break;
}
}
else if(arr1[i].constructor==arr2[j].constructor){
narr1[i]=true;
narr2[j]=true;
break;
}
}
}
}
for(var i=0;i<arr1.length;i++){
if(narr1[i]!=true){
return false;
break;
}
}
return true;
}
else
return false;
}