javascript 数组去重复(在线去重工具)
在线文本去重复工具
第一种方法:
<textareaid="list"class="toolarea">毛票票
www.nhooo.com
www.baidu.com
www.nhooo.com
毛票票
shouce.jb51.net
www.nhooo.com
tools.jb51.net
www.baidu.com
shouce.jb51.net
tools.jb51.net
毛票票
www.nhooo.com</textarea>
<inputtype="button"onclick="process()"value="去重处理"class="bt-green">
<scripttype="text/javascript">
functionunique(ary){
vari=0,
gid='_'+(+newDate)+Math.random(),
objs=[],
hash={
'string':{},
'boolean':{},
'number':{}
},p,l=ary.length,
ret=[];
for(;i<l;i++){
p=ary[i];
if(p==null)continue;
tp=typeofp;
if(tpinhash){
if(!(pinhash[tp])){
hash[tp][p]=1;
ret.push(p);
}
}else{
if(p[gid])continue;
p[gid]=1;
objs.push(p);
ret.push(p);
}
}
for(i=0,l=objs.length;i<l;i++){
p=objs[i];
p[gid]=undefined;
deletep[gid];
}
returnret;
}
functionprocess(){
list=document.getElementById('list');
arr=list.value.split('\n');
arr=unique(arr);
list.value="";
for(keyinarr){
list.value+=arr[key]+'\n';
}
alert("处理完成!");
}
</script>
第二种方法
functionsx(){
varrntArray=[],temp,hasValue;
vararray=document.getElementById("neirong").value.split("\n");
for(variinarray){
temp=array[i];
hasValue=false;
for(varjinrntArray){
if(temp===rntArray[j]){
hasValue=true;
break;
}
}
if(hasValue===false){
rntArray.push(temp);
}
}
document.getElementById("neirong1").value=rntArray.join("\n");
}
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下