Share via


slice Method (String) (JScript 5.6) 

Returns a section of a string.


stringObj.slice(start, [end]) 

Arguments

  • stringObj
    Required. A String object or literal.
  • start
    Required. The index to the beginning of the specified portion of stringObj.
  • end
    Optional. The index to the end of the specified portion of stringObj.

Remarks

The slice method returns a String object containing the specified portion of stringObj.

The slice method copies up to, but not including, the element 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.

Example

In the following example, the two uses of the slice method return the same result. In the second example, negative one (-1) points to the last character in str1 as the ending point.

str1.slice(0)

str2.slice(0,-1)

Requirements

Version 3

Applies To: String Object (JScript 5.6)

See Also

Reference

Array Object (JScript 5.6)
slice Method (Array) (JScript 5.6)