Manipulate String Object Using JavaScript substring() Method

If we often used JavaScript language for web programing, sometimes we need to manipulate string object. There are many kind of string manipulation method on JavaScript. But Now I want to play with "substring()" method.

JavaScript substring() method extracts characters in a string between two specified index value. "substring()" syntax is

stringObject.substring(Start-Index,Stop-Index)

Start-Index value is numeric and this value is required for start the extraction index. Stop-Index value is numeric and it's optional. To extract characters from the end of the string object use negative Start-Index value. Start-Index starts at 0 and if the Stop-Index is omitted, substring() method will extracts from Start-Index to the end of the string object.

1. This is the example using substring() method without Stop-Index :

   1: <script type="text/javascript">//<![CDATA[
   2: var sObj ="Manipulate String";
   3: alert(sObj.substring(5));
   4:  //]]></script>

The example above will give the alert result "ulate String" , without double quotes.

2. This is the example using substring() method with Stop-Index :

   1: <script type="text/javascript">//<![CDATA[
   2: var sObj ="Manipulate String";
   3: alert(sObj.substring(5,13));
   4:  //]]></script>

And the result for script above is "ulate St", without double quotes.