JavaScript substr method
The substr method is used to intercept strings based on the start position and length and return to intercept part of the string. The syntax is as follows:
The code copy is as follows:
str_object.substr(start, length)
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| start | Required. The position to be intercepted starts, starts from 0; if it is a negative number, starts from the end of the string (tested, invalid in some browser versions) |
| length | Optional. Refers to the length of the string to be intercepted, omitted until the end of the string |
Tip: The substr method does not comply with the ECMAscript standard, so it is not recommended to use it.
substr method example
The code copy is as follows:
<script language="JavaScript">
var str = "www.VeVB.COM";
document.write( str.substr(4,5) );
</script>
Run this example, output: jb51
The code copy is as follows:
jb51