报错:array is undefined 求指正**
<!DOCTYPE html> <head> <meta charset = 'utf-8'> <title>判断数组相似</title> </head> <body> <div> <h1>Hello World!</h1> </div> <script type = 'text/javascript'> /*首先定义一个函数*/ function arraysSimilar(arr1,arr2){ if(!(arr1 instanceof array)||!(arr2 instanceof array)) return false; if(arr1.length!==arr2.length) return false; var i, arr1Type = {}, arr2Type = {}; for(i=0;i<arr1.length;i++) { if(typeof(arr1[i])){ arr1Type[i] = typeof(arr1[i]);} if(typeof(arr2[i])){ arr2Type[i] = typeof(arr2[i]);} } arr1Type.sort();arr2Type.sort(); if(arr1Type.sort().join() === arr2Type.sort().join()){ return true;} else{return false;} } arr1 = [1,5,undefined,true], arr2 = [2,false,8]; arraysSimilar(arr1,arr2); /*第一步判断是否都为数组*/ /*第二步判断长度是否相等*/ /*第三步新建两个数组放入数据类型*/ /*第四步将数组排序变成字符串然后比较*/ </script> </body>
初学,所以暂时没有按照题目要求严格区分数据类型。
报错:array is undefined
代码应该还有一些问题,求大神指正**