Returns a section of a string.
SyntaxstringObj.slice( start , [ end ])
In the first example, the slice method returns the entire string. In the second example, the slice method returns the entire string, except for the last character.
var str1 = "all good boys do fine";
var slice1 = str1.slice(0);
var slice2 = str1.slice(0,-1);
var slice3 = str1.slice(4);
var slice4 = str1.slice(4, 8);
document.write(slice1 + "<br/>");
document.write(slice2 + "<br/>");
document.write(slice3 + "<br/>");
document.write(slice4);
Remarks
The slice method returns a String object containing the specified portion of stringObj.
The slice method copies up to, but not including, the character indicated by end.
If start is negative, it is treated as length + start where length is the length of the string. If end is negative, it is treated as length + end. If end is omitted, copying continues to the end of stringObj. If end occurs before start , no characters are copied to the new string.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4