Home >Web Front-end >JS Tutorial >Getting started with the substr method of JavaScript string objects (used to intercept strings)_Basic knowledge
JavaScript substr method
Thesubstr method is used to intercept a string based on the starting position and length and return the intercepted part of the string. Its syntax is as follows:
Parameter description:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
start | 必需。开始截取的位置,从 0 开始计算;如果为负数则从字符串末尾开始计算(经测试,某些浏览器版本下无效) |
length | 可选。指要截取的字符串长度,省略则至到字符串结束 |
Tip: The substr method does not comply with the ECMAscript standard and is therefore not recommended.
substr method instance
Run this example, output: jb51