1. Create an array
var array = new Array();
var array = new Array(size);//Specify the length of the array
var array = new Array(item1,item2...itemN);//Create an array and assign values
2. Value acquisition and assignment
var item = array[index ];//Get the value of the specified element
array[index] = value;//Assign a value to the specified element
3. Add new elements
array.push(item1,item2...itemN);//Add one or more elements to the array, Return the length of the new array
array.unshift(item1,item2...itemN);//Add one or more elements to the beginning of the array, the original element position will automatically move backward, and return the length of the new array
array.splice(start,delCount,item1,item2...itemN);//Delete delCount elements backward from the start position, and then insert one or more new elements from the start position
4. Delete elements
array.pop() ;//Delete the last element and return the element
array.shift();//Delete the first element, the array element position will automatically move forward, and return the deleted element
array.splice(start, delCount);//Delete delCount elements backward from the start position
5. Merging and intercepting arrays
array.slice(start,end);//Return a part of the array in the form of an array. Note that the element corresponding to end is not included. If it is omitted end will copy all elements after start
array.concat(array1,array2); // Splice multiple arrays into one array
6. Sorting of arrays
array.reverse();//Array reverse
array.sort( );//Array sorting, return array address
7. Convert array to string
array.join(separator);//Connect the arrays with separator
I have listed all of them, but I still can’t find it. Delete the array based on the subscript. Elemental approach! So I checked some information and found a solution.
Deleting array elements requires extending the Array prototype prototype.
Generally, the subscripts of arrays are numerical, but there are also character subscripts.
To process numerical types, first write the following code, It is an extension of array
Array.prototype.del = function (dx)
{
if(isNaN(dx)||dx>this.length){return false;}
this.splice(dx,1);
}
Secondly, numeric parameters can be passed directly. For example, var arr = ["aa","bb"];arr.del(0);
Let’s talk about character subscripts
var arr = [].
arr["aa"] = 1;