JavaScript String substr() method
extracts a part of a string

substr() method extracts a part of a string.

substr() method begins at a specified position, and returns a specified number of characters.

syntax

substr(start, length)

start The index of the first character to include in the returned substring.

length (optional). The number of characters to extract.

substr() method does not change the original string.

substr() is deprecated and is no longer recommended; use substring() or slice() methods.

To extract characters from the end of the string, use a negative start position.

If start position is greater than or equal to the string length, an empty string "" is returned.

syntax 1 description
extract characters from start index to end of myString
myString.substr(start)
syntax 2 description
extract characters from start index for specified length
myString.substr(start, length)