.substring()
Anonymous contributors
Anonymous contributors
Anonymous contributors
Published Jun 21, 2021Updated Sep 3, 2021
Contribute to Docs
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
All contributors
- Anonymous contributorsAnonymous contributors
- Anonymous contributors
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.