Rumah  >  Artikel  >  hujung hadapan web  >  javascript下过滤数组重复值的代码_javascript技巧

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

WBOY
WBOYasal
2016-05-16 19:09:07908semak imbas




<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>
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn