JS Remove repeating character method in string

Source: Internet
Author: User
Tags array length button type split

  This article mainly describes how to delete the characters in the string, the need for friends can refer to the following

  Code as follows: <! DOCTYPE html>  <html>  <head>  <script src= "//ajax.googleapis.com/ajax/libs/jquery /1.8.3/jquery.min.js ">  </script>  <script>  $ (document). Ready (function () {  $ (" Button "). Click (function () {  var str=$ (" #org "). Val ();  var arr=str.split (" ");  for (Var i=0; arr.length-1>i;i++) {  for (var j=i+1;j<arr.length;j++) {  if (arr[j]==arr[i)) {  alert (arr.length );  Arr.splice (j,1); After deletion, the array length decreases   j--; } } }  alert (arr.tostring ()); //$ ("#dl"). Val (arr.tostring ()) ;//generated strings separated by commas     $ ("#dl"). Val (Arr.join (""));//generated string no split character     $ ("#dl"). Val (Arr.join ("-")); The Join method can specify the delimiter   $ ("#dl") of the generated string. attr ({"Style": "}); })  });  </script>  </head>   <body>  <input id= "org" type= "text" value= "Hhuummqqhhuummss"/>  <button type= "button" > Remove duplicate </button>  <input id= "DL" tYpe= "text" style= "Display:none"/>  </body>  </html> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.