string slice
JavaScript | 字符串slice()方法 (JavaScript | String slice() Method)
The String.slice() method in JavaScript is used to return a part of the string. The starting and ending index of the part to be sliced is provided as the parameter of the string.
JavaScript中的String.slice()方法用于返回字符串的一部分。 提供要切片的部分的开始和结束索引作为字符串的参数。
Syntax:
句法:
String.slice(startIndex, endIndex);
Parameter(s):
参数:
The method accepts two parameters, they are the starting and ending index of the sliced string which is extracted.
该方法接受两个参数,它们是提取的切片字符串的开始和结束索引。
Return value:
返回值:
The return type of this method is string which is the sliced output of the given string.
此方法的返回类型是string ,它是给定字符串的切片输出。
Browser support: Chrome, Internet explorer, Mozilla, Safari, Opera mini.
浏览器支持: Chrome,Internet Explorer,Mozilla,Safari,Opera mini。
Example:
例:
str = "includehelp"
//"includehelp"
str.slice(6)
//"ehelp"
str.slice(0,7)
//"include"
str.slice(6,-1)
//"ehel"
翻译自: https://www.includehelp.com/code-snippets/string-slice-method-with-example-in-javascript.aspx
string slice