JavaScript String method : substring()

The JavaScript substring(beginIndex, endIndex) method is used to copy or extract a part of the string strat from the index position beginIndex till the endIndex. Where the parameters beginIndex shows the start position and the parameter endIndex shows the end position. lets see the below example :
<html>
<body>
  <script>
    var str = "Hello world!!.";
    var newStr = str.substring(6, 11); 
    document.write(newStr);
  </script> 
</body>
</html>
Output :


And if we provide only one parameter then it slice all the characters after that position.
<html>
<body>
  <script>
    var str = "Hello world!!.";
    var newStr = str.substring(6); 
    document.write(newStr);
  </script> 
</body>
</html>
Output :



Next Topic :