JavaScript Substr
Substr function of JavaScript also returns the part of a string of specified length starting from the start index. Here specified length means it returns the number of characters.
Syntax
stringObject.substr([startIndex], optinal [length]);
Substr function takes two parameters one as a starting point from which it starts the sub string. Second parameter is optional that takes as a length of string to be returned by the substr function. If you will not pass the length then it returns the sub string starting from the specified index to the end of provided string.
JavaScript String Object Examples:
You can see the live samples and examples of JavaScript String Object from the following links:
Example of JavaScript substr function
var myString = new String(); myString = "JavaScript SubStr"; document.write(myString.substr(4, 10));
In the above example starting from 0 as the index of first character of the string you will get the following output result:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| J | a | v | a | S | c | r | i | p | t | S | u | b | S | t | r | |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
Example of JavaScript substr with length parameter
var myString = new String(); myString = "JavaScript SubStr"; document.write(myString.substr(4));
You will get the returned sub string starting from the passed index to the end of string
Output:
You can see the output of above discussed code from the following links:
Continue to next tutorial: Javascript String Function to learn how to convert an object into string value.

* will not be published
* hint: http://www.example.com