博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

javascript 数据去重

Posted on 2019-06-14 14:50  taigudaren  阅读(80)  评论(0编辑  收藏  举报
Array.prototype.unique=function(){
var i,tmpArr=[];
for(i in this){
if(typeof this[i]!='function'){
if(tmpArr.join(',').indexOf(this[i])==-1){
tmpArr.push(this[i]);
}
}
}
return tmpArr;
}
var arr=['a','b','a','c','c','ab','bc'];
var r=arr.unique();
console.log(r);