JavaScript String substring() method
returns part of the string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied

substring() method extracts part of the string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.

syntax

substring(start, end)

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

end (optional). The index of the first character to exclude from the returned substring.

substring() method extracts characters from start to end (exclusive).

substring() method does not change the original string.

If start is greater than end, arguments are swapped: (4, 1) = (1, 4).

Start or end values less than 0, are treated as 0.

syntax 1 description
extract characters from start index to end of myString
myString.substring(start)
syntax 2 description
extract characters from start index to end index (exclusive)
myString.substring(start, end)