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

js method to filter duplicate elements of array_javascript skills

WBOY
Release: 2016-05-16 18:20:15
Original
1076 people have browsed it
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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template