JavaScript Array Splice function

Source: Internet
Author: User
Tags javascript array

// the original array var array = ["One", "one", "four"]; // Splice (position, Numberofitemstoremove, item) // stitching function (index position, number of elements to delete, Element)Array.splice (2, 0, "three"); array;   // now the array is like this ["one", "Three ", "four"]
function (Index, item) {  this. Splice (index,0, item);}; You can do this later with var nums = ["One", "one", "one", "four"];nums.insert (//  Note Array index, [0,1,2 ...] Array    //  ["One", "one", "three", "four"]
The instance extracts two elements from position 2 and adds a new element to the 2nd position in the array: var fruits = ["Banana", "Orange", "Apple", "Mango"];fruits.splice (2,2); Fruits output: Banana, Orange

Parameter values
Parameters Description
Index Necessary. Specifies where to add/remove elements from.
This parameter is the subscript that begins inserting and/or deleting an array element, which must be a number.
Howmany Necessary. Specifies how many elements should be deleted. Must be a number, but it can be "0".
If this parameter is not specified, all elements from index start to the end of the original array are deleted.
item1, ..., ItemX Optional. The new element to add to the array
return value

Type Description
Array If the element is removed from the Arrayobject, the array containing the deleted element is returned.

JavaScript Array Splice function

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.