substr Definition and Usage The
substr() method can extract the specified number of characters starting from the start subscript in a string.
Syntax
stringObject.substr(start,length)
参数 | 描述 |
---|---|
start | 必需。要抽取的子串的起始下标。必须是数值。如果是负数,那么该参数声明从字符串的尾部开始算起的位置。也就是说,-1 指字符串中最后一个字符,-2 指倒数第二个字符,以此类推。 |
length | 可选。子串中的字符数。必须是数值。如果省略了该参数,那么返回从 stringObject 的开始位置到结尾的字串。 |
In this example we will use substr() to extract some characters from a string:
[Ctrl A Select All Note: If you need to introduce external Js, you need to refresh to execute
]
Output:
lo world!
Example 2
[Ctrl A Select All Note:
]
Output:
lo worl