JS Splice Remove or add elements from a location in an array

Source: Internet
Author: User

Inserting or deleting an element using the splice () method requires the following three parameters
-Start index (where you want to start adding elements)
-the number of elements to delete, which is 0 when the element is added
-Elements that you want to add into the array

varNums = [1,2,3,4,5,6]nums.splice (3,0,1,0,2); Nums//operating Results [1, 2, 3, 1, 0, 2, 4, 5, 6]varNums = [1,3]nums.splice (2,0,1,0,2); Nums//operating Results [1, 3, 1, 0, 2]  //Delete ElementvarNums = [1,2,3,4,5,6]nums.splice (2,3); Nums//operating Results [1, 2, 6]varNums = []nums.splice ()//Nums.splice, it's useless to delete more.Nums//running Results [1]

JS Splice Remove or add elements from a location in an array

Related Article

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.