Returns a section of a string.
stringObj.slice(start, [end])
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 where length is the length of the string. If end is omitted, extraction continues to the end of stringObj. If end occurs before start, no characters are copied to the new string.
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.
str1.slice(0) str2.slice(0,-1)
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.
Applies To: String Object (JavaScript)