JavaScript substring() Method
JavaScript String object
Definition and Usage
The substring() method is used to extract the characters in a string between two specified indices.
The substring returned by the substring() method includes at the beginning the character at the start position but does not include the character at the *end* position.
Syntax
string
.substring(from, to)
| Parameters | Description |
|---|---|
| from | Required. A non-negative integer that specifies the position of the first character of the substring to extract in string Object. |
| to | Optional. A non-negative integer that is one more than the position of the last character of the substring to extract in string Object. |
| If this parameter is omitted, the returned substring extends to the end of the string. |
Browser support





All major browsers support the substring() method.
Example
Example
In this example, we will use substring() to extract some characters from the string::
The output of the above code:
lo world!
lo w
Try it »
JavaScript String object