Removing a comma or semicolon from the end of a string if present -using javascript - Javascript String Operation

Javascript examples for String Operation:String Remove

Description

Removing a comma or semicolon from the end of a string if present -using javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// w  ww.j av  a  2  s  .  co  m
var your_string = 'Joe, Loe, David, Ted,';

your_string = your_string.replace(/[,;]$/,'');

var your_string2 = 'AAA, BBB, 999, CCC,;';

your_string2 = your_string2.replace(/[,;]$/,'');

document.write(your_string + '<br/>' + your_string2);

    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials