Home  >  Article  >  Web Front-end  >  JS method to delete duplicate characters in string_javascript skills

JS method to delete duplicate characters in string_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:56:251164browse
Copy code The code is as follows:





<script> <br>$(document).ready(function(){ <br>$("button").click(function(){ <br>var str=$("#org").val (); <br>var arr=str.split(""); <br>for(var i=0;arr.length-1>i;i ){ <br>for(var j=i 1;j&lt ;arr.length;j ){ <br>if(arr[j]==arr[i]){ <br>alert(arr.length); <br>arr.splice(j,1); //Delete After that, the array length is reduced accordingly <br>j--; <br>} <br>} <br>} <br>alert(arr.toString()); <br>//$("#dl") .val(arr.toString());//The generated strings are separated by commas <br><br>$("#dl").val(arr.join(""));//The generated characters String without delimiter<br><br>$("#dl").val(arr.join("-"));//join method can specify the delimiter of the generated string<br>$("# dl").attr({"style":""}); <br>}) <br>}); <br></script>







Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn