An increase in the array
Ary.push ()
Adds an element to the end of the array, returns the length of the new array added, and the original array changes
Ary.unshift ()
Adds an element to the beginning of the array, returns the length of the new array added, and the original array changes
var ary=[1,2,3,4];
var res=ary.unshift (6);
Console.log (RES); ---->5
Returns the length of the new array ary.splice (n,m,x) deletes the M element from the index n, puts the new element x in front of the index n, returns the deleted element as a new array, and changes the original array.
Ary.splice (n,0,x)
Deletes 0 elements from index N, puts the newly added element x before the index n, returns an empty array, and changes the original array.
Ary.splice (n,m)
Delete m elements from index n, return the deleted content as a new array, and change the original array
Splice (0,0,x)----->unshift
The deletion of an array
Ary.pop () deletes the last item of the array, returns the deleted item, and the original array changes
Ary.shift () deletes the first item of the array, returns the deleted item, and the original array changes
var ary=[5,8,3,4,6];var res=ary.shift (); Console.dir (res);---->5 returns the first item of the array • Deletes the contents of the last item in the array Ary.splice (ary.length-
1,1)//ary.length-1 the contents of the last item of the array ary.length-=1 ary.length--
var ary=[5,8,3,4,6];//
Ary.splice (ary.length-1,1);
Ary.length-=1;
Console.dir (ary);---->
Query and copy of [5,8,3,4] array output
Slice (n,m) starts at index N, finds the index m, returns the found content as a new array, and does not change the original array
Slice (n-1,m) extracts the nth item of an array to M
Slice (n) finds the end of the array starting at index n
Slice (0) slice () copy an existing array into an array clone
concat () can also implement array cloning
Concat's intention is to implement the concatenation of arrays Ary.concat (Ary2) to stitch two arrays
Array into a string
tostring Each item of the array, separated by commas, and the original array is unchanged.
Join ("+") takes each item of the array and separates it with the specified delimiter
• Array summation
var ary=[5,8,3,4,6];
var str=ary.join ("+");
var total=eval (str);
Console.dir (total); Converts the specified string into a true expression executing
var ary=[5,8,3,4,6];
var total=0;
for (Var i=0;i<ary.length;i++) {
total+=ary[i];
}
arrangement and sorting of arrays
reverse () sort the array upside down, and the original array changes
sort can be done from large to small or from small to large, but direct write sort can only be sorted within 10 of the number Ary.sort (function (a,b) {return (a-b);})
Some common methods, but not compatible.
The indexof () method returns the location of the first occurrence of a specified string value in a string.
foreach
Map
will be in the future of the virtual seats continue to complement the hope that can help you understand learning together.
Above this article on the JavaScript in the array of additions and deletions is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.