【记录】简单去除数组重复项
不能处理太复杂的数组。比如数组项目本来就是数组,或者是对象(object)
var clearRepeat=function(a){
var c=[],b={};
for(var i=0;i<a.length;i++){
if( ! b[0+a[i]]){
b[a[i]]=1;
c.push(a[i])
}
}
return c;
}
var a=[undefined,4,5,6,7,8,9,10,11,"aa","bb","aa","bb","$#@@","!*&^%%","$#@@","!*&^%%",0,"0"];
//请注意上面数组的0,"0"项目。是可以正常处理的。因为他们的数据类型不一样所以他不能算是重复项
var c=clearRepeat(a);
alert(c.join())
推荐文章:删除数组中重复项(uniq)