JS inserts/deletes data at the specified position in the array. js Array

Source: Internet
Author: User

JS inserts/deletes data at the specified position in the array. js Array

The splice () method adds/deletes a project to/from the array, and then returns the deleted project.

Syntax

ArrayObject. splice (index, howmany, item1,..., itemX)

Parameter description

Parameters Description
Index Required. Integer that specifies the position of the added/deleted project. A negative number can be specified from the end of the array.
Howmany Required. The number of projects to delete. If it is set to 0, the project will not be deleted.
Item1 ,..., ItemX Optional. Add a new project to the array.

Instance

Add an element

Var array = [, 6]; array. splice (, 5 );

Result: array is [1, 2, 3, 4, 5, 6].

Delete and replace an element

Var array = [1, 2, 4, 5]; array. splice (2, 1, 2 );

Result: array is [1, 2, 3, 4, 5].

The above is all the JS insert/delete data in the specified position of the array provided by xiaobian. I hope you can support more help ~

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.