Slice (), splice (), split (), substring (), substr () method of Use

Source: Internet
Author: User

1.slice ();

Array and String objects have

Slice in Array (i, [J])

I as the index value to begin intercepting, the negative number represents the index value from the end, and 1 is the first element in the countdown.
J is the end of the index value, and the default is to get all elements from I to the end

Parameter returns:
Returns an array of index values from I to J, the original array does not change

Slice in String (i, [J])

Parameter description:
i is the index value to start intercepting, the negative number represents the index value from the end, 1 is the first character
J is the end of the index value, and the default is to get all the characters from I to the end

2.splice ()

exists in Array  method adds/Deletes an item to/from the array, and then returns the item that was deleted. the method will change the original array

Splice (INDEX,HOWMANY,ITEM1,ITEMX)

Index : required. An integer that specifies the location of the Add/remove item, using a negative number to specify the position from the end of the array.

Howmany : Required. The number of items to delete. If set to 0, the item is not deleted.

item1...itemx :  optional. Adds a new item to the array.

return value Array contains the new array of deleted items, if any.

3.split ()

in string ? ? Split (Separator,howmany) ? ?

Separator : required. A string or regular expression that splits stringobject from where specified by the parameter.

Howmany : Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length.

? return value

An array of strings. The array is created by splitting the string stringobject into substrings at the boundary specified by separator. The string of the returned array does not contain the separator itself

However, if Separator is a regular expression that contains a subexpression, the returned array includes strings that match those sub-expressions (but does not include text that matches the entire regular expression)

Opposite effect to jion () function

4.substring ()

In string substring (start,stop)

Start : represents the starting position of a substring,

Stop : indicates the end result.

Note: The second parameter should be greater than the first one. If the first argument is greater than the second argument, the substring method automatically replaces the position of the two parameter.  

4.substr ()

In string, substr (start,length);

Start : The start position of the substring,

length : The length of the substring.



Slice (), splice (), split (), substring (), substr () method of use

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.