Languages
[Edit]
EN

JavaScript - String substring() method example

14 points
Created by:
Aisha
418

1. Documentation

Edit
SyntaxString.prototype.substring(indexStart[, indexEnd])
Parameters

indexStart - integer between 0 and a number one less than the string length.

indexEnd (optional) - integer between 0 and the length of the string.

ResultA new string containing the specified part of the given string.
DescriptionString substring returns the part of the string between the indexStart and indexEnd, or from indexStart to the end of the string.

2. String substring with one argument example

Edit

The example presented in this section shows how to get substring starting from the index passed as the first argument to the end of the string.

3. String substring with two arguments example

Edit

The example presented in this section shows how to get substring starting from the index passed as the first argument to the ending index passed as the second argument.

4. String substring with swapped arguments example

Edit

In this case, the substring behaves similarly to the second example. One difference is if the first argument is bigger than the second one then they are swapped.

5. String substring with negative arguments example

Edit

When arguments are negative then they are converted to 0.

Alternative titles

  1. JavaScript - cut text from string
  2. JavaScript - cut substring from string
  3. JavaScript - String.prototype.substring() documentation with examples
  4. js - String substring() method documentation with examples
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - String (documentation)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join