Splice () method of arrays in JS

Source: Internet
Author: User

In the array, the Splice method has the function of increasing, deleting, and the utility.

varList = []; List.push (1); List.push (2); List.push (3); Console.log (list); //[1, 2, 3]                //DeleteList.splice (0,1);//Delete, starting with subscript 0, length 1Console.log (list);//[2,3]List.splice (0,2);//Delete, starting with subscript 0, length 2Console.log (list);// []                //ReplaceList.splice (0,1,4);//Replace, starting with subscript 0, 1-length array element replaced by 4Console.log (list);//[4,2,3]List.splice (0,2,4);//Replace, starting with the subscript 0, the array element with length 2 is replaced with 4 (that is, the 4,2 is replaced with a whole of 4)Console.log (list);//[4,3]                //AddList.splice (1,0,5);//indicates that an item is added at Subscript 1 5Console.log (list);//[1,5,2,3]

Splice () method of arrays 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.