js过滤数组重复元素:
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