About the slice () and splice () Methods of arrays

Source: Internet
Author: User

Slice () is to create a new array (so you cannot

Array.slcie (1,4) Do you have to assign var a = Array.slice (1,4) to a variable like this? ), and the return value of this example is an array of 1 to 3 (No 4) entries splice () are operated on the original array, so it can be array.splice (1,4) or var a = Array.splice (1,4) but note that SPL The 1 meanings of 1 and slice (1,4) in ice (1,4) are the same, which means starting with an array index of 1, but 4 of splice () means the number of items to be deleted, while the 4 of Slice () represents the end of the previous, or 4, of the array index 3. The return values of slice () and splice () are all "cut" values. For Array.splice (2,0, "orange", "purple"), here the 2 can be expressed in the array index value 2 before the insertion, that is, the 3rd value of the array is inserted before, of course, it can be understood to be inserted after the 2nd value of the array, it is best to remember only one of them lest confuse

About the slice () and splice () Methods of arrays

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.