.substring()
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:
Contribute to Docs
- 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.