javascript下过滤数组重复值的代码_javascript技巧
- WBOY原創
- 2016-05-16 19:09:07906瀏覽
<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