.substring()

Armstrong20355 total contributions
Published Jun 21, 2021Updated Aug 8, 2023
Contribute to Docs
The .substring()
method returns a part of a string from a given starting index or between the start and end index. The index starts at zero.
Syntax
myString.substring(startIndex, endIndex);
startIndex
is the starting index from which the returned substring will cover.endIndex
is optional. It defaults to cover the rest of the string.
Example
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?
Codebyte Example
Returning a part of a string between start and end index:
All contributors
- Armstrong20355 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor51 total contributions
- Armstrong2035
- christian.dinh
- Anonymous contributor
- Anonymous contributor
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.