我要变好呀
2019-04-26 18:14
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030">
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
/*
* param1 Array
* param2 Array
* return true or false
*/
function arraysSimilar(arr1, arr2){
if(!Array.isArray(arr1)||!Array.isArray(arr2)||arr1.length!==arr2.length){
return false;
}
var a,b,c,d,e,f,g,h=0;
for(var i=0;i<arr1.length;i++){
var select=Object.prototype.toString.apply(arr1[i]);
switch(select){
case "[object String]":
a=a+1;
break;
case "[object Boolean]":
b=b+1;
break;
case "[object Number]":
c=c+1;
break;
case "[object Undefined]":
d=d+1;
break;
case "[object Null]":
e=e+1;
break;
case "[object Function]":
f=f+1;
break;
case "[object Array]":
g=g+1;
break;
case "[object Object]":
h=h+1;
break;
default:
break;
}
var secect1=Object.prototype.toString.apply(arr2[i]);
switch(select1){
case "[object String]":
a=a-1;
break;
case "[object Boolean]":
b=b-1;
break;
case "[object Number]":
c=c-1;
break;
case "[object Undefined]":
d=d-1;
break;
case "[object Null]":
e=e-1;
break;
case "[object Function]":
f=f-1;
break;
case "[object Array]":
g=g-1;
break;
case "[object Object]":
h=h-1;
break;
default:
break;
}
}
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0&&h==0){
return true;
}
else{
return false;
}
}
</script>
<script src="testData.js"></script>
</body>
</html>
而且你这两个单词不一样,会报错的
你这方法写好了没有调用呀
var secect1=Object.prototype.toString.apply(arr2[i]);
secect1 拼错了
JavaScript深入浅出
281100 学习 · 1020 问题
相似问题