JS Array deletes elements based on subscript

Source: Internet
Author: User
Tags array sort sort

1. Create an array

The

code is as follows:


var array = new Array ();


var array = new Array (size);//Specifies the length of the array


var array = new Array (item1,item2......itemn);//Create an array and assign a value

2, take value, assign value

The

code is as follows:


var item = array[index];//Gets the value of the specified element


Array[index] = value;//Assign value to the specified element

3. Add new elements

The

code is as follows:


Array.push (ITEM1,ITEM2......ITEMN);//Add one or more elements to the array, returning the length of the new array


Array.unshift (ITEM1,ITEM2......ITEMN);//Adds one or more elements to the beginning of the array, the original element position is automatically moved back, and the length of the new array is returned


Array.splice (START,DELCOUNT,ITEM1,ITEM2......ITEMN);//Remove delcount elements from the start position and insert one or more new elements from the start position

4, delete elements

The

code is as follows:


Array.pop ()//deletes the last element and returns the element


array.shift ()//delete the first element, the array element position is automatically moved forward, and the deleted element is returned


Array.splice (Start,delcount);//delete delcount elements from start position

5, the integration of the array, interception

The

code is as follows:


Array.slice (start,end);


//Returns a portion of an array as an array, noting that the end-corresponding element is not included, and if the end is omitted all elements after start are copied


Array.concat (array1,array2);


//concatenation of multiple arrays into an array

6, sorting the array

The

code is as follows:


array.reverse ();//array inversion


Array.Sort ();//array sort, return array address

7, the array of the string

Array.join (separator);//connect array reason with separator

That's all there is to find a way to delete an array element! So I looked up some information and found a solution.
Removing an array element requires extending the array prototype prototype.

 
1 2 3 4 5 6 7 8 9 10 11 Array.prototype.del=function (Index) {if (isNaN) | | Index>=this.length) {return false;} for (Var i=0,n=0;i if (This[i]!=this[index)) {this[n++]=this[i];} this.length-= 1; };
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.