JavaScript substr Method
The Substr method is used to intercept a string based on the start position and length and return an intercept part string. The syntax is as follows:
Copy Code code as follows:
Str_object.substr (start, length)
Parameter description:
Parameters |
Description |
Str_object |
The string to manipulate (object) |
Start |
Necessary. The position at which to begin the interception, calculated from 0, or, if negative, from the end of the string (tested, invalid under some browser versions) |
Length |
Optional. The length of the string to intercept, omitted to the end of the string |
Hint: The substr method does not conform to the ECMASCRIPT standard and is therefore not recommended.
Substr Method Instance
Copy Code code as follows:
<script language= "JavaScript" >
var str = "Www.jb51.net";
document.write (Str.substr (4,5));
</script>
Run the example, output: jb51
Copy Code code as follows: