首页  >  文章  >  web前端  >  javascript下过滤数组重复值的代码_javascript技巧

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

WBOY
WBOY原创
2016-05-16 19:09:07908浏览




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



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




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




<script> <BR>var s = "0,1,2,5,3,2,12,4,1,1,123450"; <BR>var sTmp = (","+s.split(",").reverse().join(",")+",").replace(/,([^,]+)(?=,.*,\1,)/ig, '').split(",").reverse().join(); <BR>sTmp = sTmp.substr(1, sTmp.length-2); <BR>alert(sTmp) <BR></script>




<script> <BR>var strArr = "123450,0,1,2,5,3,2,12,4,1,1,123450".split(",") <BR>var str = "," <BR>for(i = 0; i < strArr.length; i++) <BR>{ <BR> if(str.indexOf("," + strArr[i] + ",") == -1)str += strArr[i] + "," <BR>} <BR>alert(str.substring(1,str.length - 1)) <BR></script>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn