Home  >  Article  >  Web Front-end  >  js method to filter duplicate elements of array_javascript skills

js method to filter duplicate elements of array_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:20:151058browse
Copy code The code is as follows:

function filterArray(str,array){ //This function is a filter array Duplicate elements in and do not allow to insert null values, the function returns the 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;
}

Reposted from:http://www.52blogger. com/archives/588
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn