Slice method (String)

Source: Internet
Author: User
Tags array object end string

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.