<pre name="code" class="javascript"><script type="text/javascript">
Array.prototype.distinct = function(){
for(var i = 0;i<this.length;i++){
var n = this[i ];
this.splice(i,1,null);
if(this.indexOf(n) < 0){
this.splice(i,1,n);//不存在重复
}else{
this.splice(i,1);//存在重复
}
}
return this;
};
//当有一个数组a要去重时
var a=["1","1","2","3","3","3"];
a.distinct();//调用此句就可以去重了
alert(a);//运行结果就为1,2,3
</script>
js数组元素去重
最新推荐文章于 2024-06-01 07:27:22 发布