The string value to return the substring from.
The index of the first character to include in the returned substring.
OptionalindexEnd: numberThe index of the first character to exclude from the returned substring.
A new string containing the specified part of the given string
const anyString = 'Nevware21';
// Displays 'N'
console.log(strSubstring(anyString, 0, 1));
console.log(strSubstring(anyString, 1, 0));
// Displays 'Nevwar'
console.log(strSubstring(anyString, 0, 6));
// Displays 'are21'
console.log(strSubstring(anyString, 4));
// Displays 'are'
console.log(strSubstring(anyString, 4, 7));
// Displays '21'
console.log(strSubstring(anyString, 7, 4));
// Displays 'Nevware'
console.log(strSubstring(anyString, 0, 7));
// Displays 'Nevware21'
console.log(strSubstring(anyString, 0, 10));
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:indexEndis omitted, strSubstring() extracts characters to the end of the string.indexStartis equal to indexEnd, strSubstring() returns an empty string.indexStartis 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.lengthis treated as if it were 0 andvalue.length, respectively.Any argument value that is NaN is treated as if it were 0.