关于 JS 中三维数组和一维数组的比较问题··
在 JS 里面有两个数组
一个是 arrSelect[i]={x,y,z}
比如:
arrSelect[0]={ "1 ", "2 ", "3 "}
arrSelect[1]={ "23 ", "11 ", "31 "}
arrSelect[2]={ "112 ", "221 ", "312 "}
..............
一个是 collectSelect[i]={z}
比如:
collectSelect[0]={ "3 "}
collectSelect[1]={ "31 "}
collectSelect 里面的值 都是从 arrSelect的arrSelect[i][2] 取出来的
现在要取出 arrSelect[i][2]!=collectSelect[j]
情况下的 arrSelect[i]
------解决方案--------------------在js里面数组是用 "[] "定义的,而不是 "{} "
collectSelect[i]=[z];
这是一个数组,不能用 "!= "比较
必须先转化为字符串
用collectSelect[i][0]或者collectSelect[i].join( " ")都可以
都是指向字符串z
<script language= "javascript ">
var arrSelect=new Array();
arrSelect[0]=[ "1 ", "2 ", "3 "];
arrSelect[1]=[ "23 ", "11 ", "31 "];
arrSelect[2]=[ "112 ", "221 ", "312 "];
var collectSelect=new Array();
collectSelect[0]=[ "3 "]
collectSelect[1]=[ "31 "]
for(var i=0;i <arrSelect.length;i++){
var has=false;
for(var j=0;j <collectSelect.length;j++){
if(arrSelect[i][2]==collectSelect[j].join( " ")){
//if(arrSelect[i][2]==collectSelect[j][0]){
has=true;
}
}
if(!has){alert( "collectSelect里面没有: "+arrSelect[i][2]);}
}
</script>