首頁 > web前端 > js教程 > javascript下过滤数组重复值的代码_javascript技巧

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

WBOY
發布: 2016-05-16 19:09:07
原創
933 人瀏覽過




<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>
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板