Returns a fragment of a string.
stringObj.slice(start, [end])
Parameters
Stringobj
Required option. is a String object or literal.
Start
Required option. The subscript specifies a partial starting index with the stringobj starting at 0.
End
Options available. The subscript ends with the specified portion of the stringobj starting with 0.
Description
The slice method returns a String object that contains the specified portion of the stringobj .
The slice method is copied to the element specified by end, but does not include the element. If start is negative, it is the length + start processing, where length is the size of the array. If end is negative, it is treated as length + end where length is the length of the array. If End is omitted, the slice method is copied to the ending of arrayobj . If end appears before start , no elements are copied into the new array.
Example
In the following example, the two usages of theslice method will return the same result. The second example, 1, points to the last character in the str1 and serves as the end position for the fetch operation.
str1.slice(0)str2.slice(0,-1)
Requirements
Version 3
Please see
Array Object | Slice Method (Array) | method of a String object
Apply to: String Object