Definitions and usage
The substring () method extracts characters from a string mediation between two specified subscripts.
Grammar
stringobject.substring (start,stop)
return value
A new string that contains a substring of stringobject whose contents are all characters from the start to the stop-1, whose length is stop minus start.
Description
The substring returned by the substring () method includes the character at the start, but does not include the character at the stop.
If the argument start is equal to the stop, the method returns an empty string (that is, a length of 0). If start is larger than stop, the method swaps the two parameters before extracting the substring.
Tips and Comments
Important: Unlike the slice () and substr () methods, substring () does not accept negative parameters.
Example Explanation
Example 1
In this case, we'll 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 case, we'll 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 for you to share the use of JavaScript substring (), I hope that you try to do a hands-on, really grasp the use of JavaScript substring ()