The string value to return the substring from.
The index of the first character to include in the returned substring.
Optional
indexEnd: numberThe index of the first character to exclude from the returned substring.
A new string containing the specified part of the given string
The
strSubstring()
method returns the part of the string between the start and end indexes, or to the end of the string.strSubstring()
extracts characters from indexStart up to but not including indexEnd. In particular:indexEnd
is omitted, strSubstring() extracts characters to the end of the string.indexStart
is equal to indexEnd, strSubstring() returns an empty string.indexStart
is greater than indexEnd, then the effect of strSubstring() is as if the two arguments were swapped; see example below.Any argument value that is less than 0 or greater than
value.length
is treated as if it were 0 andvalue.length
, respectively.Any argument value that is NaN is treated as if it were 0.
Example