.substring()
Return a part of a string from a given starting index or between start and end index. Index starts at zero.
Syntax
string.substring(startIndex, endIndex);
endIndex
is optional.
Example 1
Returning a part of a string from a given starting index:
console.log('Do you love JavaScript or Python?'.substring(2));// Output: you love JavaScript or Python?
Example 2
Returning a part of a string between start and end index:
console.log('Do you love JavaScript or Python?'.substring(3, 6));// Output: you
Contributors
- Anonymous contributors