AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

javascript 数组去重复(在线去重工具)

51自学网 http://www.wanshiok.com
js,数组去重复

在线文本去重复工具

第一种方法:

<textarea id="list" class="toolarea">wanshiok.comwww.wanshiok.comwww.baidu.comwww.wanshiok.comwanshiok.comshouce.wanshiok.comwww.wanshiok.comtools.wanshiok.comwww.baidu.comshouce.wanshiok.comtools.wanshiok.comwanshiok.comwww.wanshiok.com</textarea><input type="button" onclick="process()" value="去重处理" class="bt-green"><script type="text/javascript">function unique(ary) { var i = 0,  gid='_'+(+new Date)+Math.random(),  objs = [],  hash = {   'string': {},   'boolean': {},   'number': {}  }, p, l = ary.length,  ret = []; for (; i < l; i++) {  p = ary[i];  if (p == null) continue;  tp = typeof p;  if (tp in hash) {   if (!(p in hash[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;  delete p[gid]; } return ret;}function process(){ list = document.getElementById('list'); arr = list.value.split('/n'); arr = unique(arr); list.value = ""; for(key in arr){	 list.value += arr[key] + '/n'; } alert("处理完成!");}</script>

第二种方法

 function sx(){  var rntArray=[],temp,hasValue;  var array=document.getElementById("neirong").value.split("/n");  for(var i in array){   temp=array[i];   hasValue=false;   for(var j in rntArray){    if(temp===rntArray[j]){     hasValue=true;     break;    }   }   if(hasValue===false){    rntArray.push(temp);   }  }  document.getElementById("neirong1").value=rntArray.join("/n"); }


js,数组去重复  
上一篇:原生js验证简洁注册登录页面  下一篇:jQuery Validate验证框架详解(推荐)