艾尔修兎
2020-01-28 23:05
<!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(arr1 instanceof Array && arr2 instanceof Array){
if(arr1.length == arr2.length){
var arr1t=[];
var arr2t=[];
var len=arr1.length
for(i=0;i<len;i++){
arr1t.push(Object.prototype.toString.apply(arr1[i]));
arr2t.push(Object.prototype.toString.apply(arr2[i]));
}
arr1t.sort();
arr2t.sort();
//document.write(arr1t+"<br>");
//document.write(arr2t+"<br>");
if(arr1t.toString()==arr2t.toString()){
return true
}
else{return false}//
}
else{return false}//长度对比失败
}
else{return false} //数组对比失败
}
</script>
<script src="testData.js"></script>
</body>
</html>
<!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 */ // var allList = [] function arraysSimilar(arr1, arr2){ return getTypeStr(arr1) === getTypeStr(arr2) } function getTypeStr(arr) { let typeList = [] arr.forEach(item => { let type = Object.prototype.toString.call(item) if (typeList.indexOf(type) < 0) typeList.push(type) }) return typeList.sort().join("") }</script><script src="testData.js"></script></body></html>
JavaScript深入浅出
281101 学习 · 1020 问题
相似问题