本文共 575 字,大约阅读时间需要 1 分钟。
字符串的slice方法
Return a new string from the part of the string included between the begin
and end
positions.
从begin
和end
位置之间包含的字符串部分返回一个新字符串。
The original string is not mutated.
原始字符串未更改。
end
is optional.
end
是可选的。
'This is my car'.slice(5) //is my car'This is my car'.slice(5, 10) //is my
If you set a negative first parameter, the start index starts from the end, and the second parameter must be negative as well, always counting from the end:
如果将第一个参数设置为负,则起始索引从末尾开始,第二个参数也必须为负,始终从末尾开始计数:
'This is my car'.slice(-6) //my car'This is my car'.slice(-6, -4) //my
翻译自:
字符串的slice方法
转载地址:http://mtqgb.baihongyu.com/