The difference between the slice () method and the Splice method ...

Source: Internet
Author: User

Defined

The splice () method is used to insert, delete, or replace elements of an array.

The slice () method extracts a portion of a string and returns the extracted part with a new string.

Usage

Splice Parameters :splice (Start, DeleteCount, [item1[, item2[, ... [, Itemn]]])

The array starts with the start subscript, deletes deletecount elements, and can begin adding n elements at this position

When start, DeleteCount is 0, the new element is inserted at the front of the array.

When the parameter only Start,deletecount is the element that deletes the DeleteCount array from the start subscript,

When the parameter has only the start parameter, it deletes the element from the start subscript to the last

When the parameter is negative, the parameter specifies the position from the end of the array element (-1 refers to the penultimate element in the array, and 2 refers to the second-to-last element in the array). )

Slice parameter: Slice (start,end);

The slice method is similar to the use of the string object and the array object.

For an array object, the slice method extracts a segment of the element (but not the end subscript element) from start that is labeled end With end, and then returns a new array that has no effect on the original array.

When the argument is negative, the argument starts at the end of the array, (1 refers to the first-to-lastelement in the array, and 2 refers to the second-to-last element in the array.) )

When the argument is a parameter, when it is a parameter, the extraction is the part of the element that is labeled start to the end.

When start is 0 o'clock, it is said to be cloning a new array, and the two arrays are cloned to perform their respective operations,

var clone = array.slice (0);

The difference between the slice () method and the Splice method ...

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.