Home > Article > Web Front-end > How to use the javascript substring() method
In JavaScript, the substring() method is used to extract the characters between two specified subscripts in the string. The syntax is "string.substring(from,to)"; the substring returned by this method includes The characters at the "from" parameter, but not including the characters at the "to" parameter.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, the substring() method is used to extract characters between two specified subscripts in a string.
Syntax:
string.substring(from, to)
Parameters | Description |
---|---|
from | Required. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the string Object. |
to | Optional. A non-negative integer that is one more position in the string Object than the last character of the substring to be extracted. If this parameter is omitted, the returned substring will go to the end of the string. The substring returned by the |
substring() method includes the characters starting at from
, but does not include the characters ending at to
.
Example:
var str="Hello world!"; console.log(str.substring(3,7));
If the second parameter is omitted, it means to extract all characters from the starting position to the end.
var str="Hello world!"; console.log(str.substring(3));
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of How to use the javascript substring() method. For more information, please follow other related articles on the PHP Chinese website!