Replace duplicated 'slash' into a single slash from a string - Javascript jQuery

Javascript examples for jQuery:String

Description

Replace duplicated 'slash' into a single slash from a string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.5.2.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){//from   w ww  .  j a v  a 2s.c  o  m
  var val = "\\val1\\val2\\val3";
  val = val.substr(0, val.lastIndexOf("\\"));
  console.log(val);
    });

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

Related Tutorials