Simple summary of Splice method and slice method in JS

Source: Internet
Author: User
Slice (start,end):

Parameters:

Start: Index of Start position

End: The index of the end position (but not the element that contains the index position)

For example:

Splice has the function of deleting, inserting, replacing

===================================================================

1: Removed features

Splice (Index,count)

Parameters:

Index: Indexing of the start position

Count: Number of elements to delete

Return: Returns the Array object that contains the deleted element

For example:

Results:

2: Insert function

Splice (index,0, inserted item)

Parameters

Index: The indexed value of the inserted element

For example:

3: Replace function

Splice (Index,num,value)

Index: the indexed position at which to start

Num: Deletes the number of items (if NUM is 0, which is the Insert function)

Value: Inserted values

Return: Returns the Array object that contains the element that was deleted

Results:

Summarize:

Slice: It's for interception.

Splice: is to do delete insert Replace with


Simple summary of Splice method and slice method in JS

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.