復制代碼 代碼如下:
function filterArray(str,array){ //此函數為過濾數組中重復的元素,並不允許插入空值,函數返回數組
var isnull = false;
if(str == "" || str == null || str == 'undefined'){
isnull = true;
}
var newnum = 0;
var newarray = [];
var num = array.length;
if(num == 0){
if(!isnull){
newarray[num] = str;
}
}else{
for(var m=0;m < num;m++){
if(str == array[m]){
break;
}else{
newarray[newnum++] = array[m];
}
}
if(!isnull){
newarray[newnum++] = str;
}
}
return newarray;
}
轉自:http://www.52blogger.com/archives/588