For example, the use of JavaScript substring (), javascriptsubstring
Definition and usage
The substring () method is used to extract characters of a string between two specified subscripts.
Syntax
StringObject. substring (start, stop)
Return Value
A new string. The value of this string contains a substring of stringObject. Its content is all characters from start to stop-1, and its length is stop minus start.
Description
The substring returned by the substring () method includes the characters at start, but not the characters at stop.
If the start parameter is the same as the stop parameter, this method returns an empty string (a string with a length of 0 ). If start is greater than stop, the two parameters are exchanged before the method extracts the substring.
Tips and comments
Important:Different from slice () and substr (), substring () does not accept negative parameters.
Instance description
Example 1
In this example, we use substring () to extract some characters from the string:
<script type="text/javascript">var str="Hello world!"document.write(str.substring(3))</script>
Output: lo world!
Example 2
In this example, we use substring () to extract some characters from the string:
<script type="text/javascript">var str="Hello world!"document.write(str.substring(3,7))</script>
Output: lo w
The above is the usage of javaScript substring () shared for you. I hope you can give it a try and learn the usage of javaScript substring ().