.substring()

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

Looking to contribute?

Learn JavaScript on Codecademy