Get sub string from a string - Javascript String

Javascript examples for String:substring

Description

Get sub string 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">
    window.onload=function(){//from w w w.  ja  v  a2 s  . co  m
var myStr = 'cocacola';
var strHalf = myStr.length / 2;
var array = [myStr.substr(0, strHalf),myStr.substr(strHalf, myStr.length)];
console.log(array);
    }

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

Related Tutorials