substring()
ES3+Returns the part of the string between the start and end indexes.
Syntax
string.substring(indexStart, indexEnd)Parameters
indexStart number Index of the first character to include
indexEnd number optionalIndex of the first character to exclude
Return Value
string
A new string containing the specified part
Examples
JavaScript
const str = 'JavaScript';
console.log(str.substring(0, 4));
console.log(str.substring(4)); Output:
// 'Java'
'Script'