function arraysSimilar(arr1, arr2){
var result = false;
var arr1Type = Object.prototype.toString.call(arr1);
var arr2Type = Object.prototype.toString.call(arr2);
var typeObj={};
if(arr1Type=='[object Array]'&&arr2Type=='[object Array]'){
result = arr1.length==arr2.length;
for(var i=0;i<arr1.length;i++){
var type = Object.prototype.toString.call(arr1[i]);
typeObj[type] = true;
}
for(var i=0;i<arr2.length;i++){
var type = Object.prototype.toString.call(arr2[i]);
if(typeof typeObj[type]!=="undefined"){
result = true;
} else {
result =false;
return result;
}
}
}
return result;
}
你确定你这个能通过吗 arr.length不会报错?而且arraysSimilar([{},{},{}],[{},{},null])返回false结果不对
?不臃肿