| 導購 | 订阅 | 在线投稿
分享
 
 
 

javascript下过滤数组重复值的代码

2008-09-09 07:29:11  編輯來源:互聯網  简体版  手機版  評論  字體: ||
 
  <script language="javascript">

  function getNoRepeat() {

  return arguments[0].join('‖').match(/(\b[^‖]+\b)(?!.*‖\1\b)/ig);

  }

  var tmpArr = [1, 'a', 'ab', 'abc', 'd', 1.2, 'a+b', 'd', 'e', 5, 'a', 1, 'h', 'c', 'ab'];

  var retArr = getNoRepeat(tmpArr);

  alert(retArr);

  </script>

  <script>

  alert("1,11,1.11,1111,111,11,1,1.11".match(/(\b\d+(?:\.\d+)?\b)(?!.*,\1\b)/g))

  </script>

  <script>

  alert("123450,0,1,2,5,3,2,12,4,1,1,123450".match(/(\b\d+\b)(?!.*,\1(,|$))/ig))

  </script>

  <script>

  alert("123450,0,1,2,5,3,2,12,4,1,1,123450".match(/(\b\d+\b)(?!(?:,[^,]+)*,\1(?:,|$))/ig))

  </script>

  <script>

  var s = "0,1,2,5,3,2,12,4,1,1,123450";

  var sTmp = (","+s.split(",").reverse().join(",")+",").replace(/,([^,]+)(?=,.*,\1,)/ig, '').split(",").reverse

  ().join();

  sTmp = sTmp.substr(1, sTmp.length-2);

  alert(sTmp)

  </script>

  <script>

  var strArr = "123450,0,1,2,5,3,2,12,4,1,1,123450".split(",")

  var str = ","

  for(i = 0; i < strArr.length; i++)

  {

  if(str.indexOf("," + strArr[i] + ",") == -1)str += strArr[i] + ","

  }

  alert(str.substring(1,str.length - 1))

  </script>
 
 
 
<script language="javascript"> function getNoRepeat() { return arguments[0].join('‖').match(/(\b[^‖]+\b)(?!.*‖\1\b)/ig); } var tmpArr = [1, 'a', 'ab', 'abc', 'd', 1.2, 'a+b', 'd', 'e', 5, 'a', 1, 'h', 'c', 'ab']; var retArr = getNoRepeat(tmpArr); alert(retArr); </script> <script> alert("1,11,1.11,1111,111,11,1,1.11".match(/(\b\d+(?:\.\d+)?\b)(?!.*,\1\b)/g)) </script> <script> alert("123450,0,1,2,5,3,2,12,4,1,1,123450".match(/(\b\d+\b)(?!.*,\1(,|$))/ig)) </script> <script> alert("123450,0,1,2,5,3,2,12,4,1,1,123450".match(/(\b\d+\b)(?!(?:,[^,]+)*,\1(?:,|$))/ig)) </script> <script> var s = "0,1,2,5,3,2,12,4,1,1,123450"; var sTmp = (","+s.split(",").reverse().join(",")+",").replace(/,([^,]+)(?=,.*,\1,)/ig, '').split(",").reverse ().join(); sTmp = sTmp.substr(1, sTmp.length-2); alert(sTmp) </script> <script> var strArr = "123450,0,1,2,5,3,2,12,4,1,1,123450".split(",") var str = "," for(i = 0; i < strArr.length; i++) { if(str.indexOf("," + strArr[i] + ",") == -1)str += strArr[i] + "," } alert(str.substring(1,str.length - 1)) </script>
󰈣󰈤
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号 wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味著赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有