JavaScript substring method
Thesubstring method is used to intercept a string by specifying the start and end positions and return the intercepted part of the string. Its syntax is as follows:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
start | 必需。开始截取的位置,非负整数 |
end | 可选。字符串截取结束的位置,非负整数;如果省略,则至字符串结束为止 |
Tip: If the parameters start and end are equal, then this method returns an empty string. If start is greater than end, the method will swap the two parameters before intercepting the string.
substring method instance
bc
The difference between substring, slice and substr
1.substring cannot accept negative parameters, but the slice method can
2. The second parameter of substring is to specify the end position of interception, and the second parameter of substr method is to specify the length of string interception