- String_Object: Please specify the valid string from which you want to extract.
- Start: Please specify the index position from where you want to extract.
- Length: This argument is optional. Please specify the number of characters you want to extract.
- If you are using the Negative numbers as first index then, SubStr() function starts from right to left.
var Str1 = "Tutorial Gateway";
The following statement will extract five characters from the original string, starting at index position 2
var Str2 = Str1.substr(2, 8);
var Str4 = Str1.substr(2);
Within the following statements, we used Negative and Zero values as second argument. As we said before, this will return empty string
var Str5 = Str1.substr(2, -3); var Str6 = Str1.substr(2, 0);
Next, we used the negative indexing. Following statement will start extracting from -3 (index position of 3 from right to left) and ends at last position.
var Str7 = Str1.substr(-3);
Thank You for Visiting Our Blog