JavaScript .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);
startIndexis the starting index from which the returned substring will cover.endIndexis 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.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours