![]() |
VOOZH | about |
The substring() is an inbuilt function in TypeScript that returns the subset of a String object. It takes two parameters: indexA (starting index) and optional indexB (ending index, non-inclusive). It returns the portion of the string between these indices.
string.substring(indexA, [indexB]) Parameter: This method accepts two parameters as mentioned above and described below:
Return Value: This method returns the subset of a String object.
Below example illustrate the String substring() method in TypeScript.
In this example we extracts a substring from str, starting at index 0 and ending at index 5.
Output:
GeeksIn this example, we demonstrate the use of substring() with different indices to extract various parts of the string.
Output:
Geeks
Geeks
s - Best P
G