Split a string using substring and indexOf - Javascript String

Javascript examples for String:split

Description

Split a string using substring and indexOf

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(){//from   ww w  .j  a  v  a 2  s.  c  o m
var a = 'Base-Shirt_Stripe.jpg';
var split = a.substring(0,a.indexOf('.')).split('_');
console.log(split[0]); //Base-Shirt
console.log(split[1]); //Stripe
    }

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

Related Tutorials