Array Arrays
methods for creating methods
1.var arr = new Array ();
Arr[0] = 1;
ARR[1] = 2;
ARR[2] = 3;
Create an array with a content of
2.var arr = new Array (5);
Create an array of length 5
3.var arr = new Array (1, 2, 3);
Create an array with a content of
4.var arr = [1, 2, 3];
Operation of the array
1. Array name. Shift ();
Deletes the first element and returns the value
var arr = [1, 2, 3];
var a = Arr.shift ();
alert (a);
Alert (arr);
2. Array name. Pop ()
Deletes the last element and returns the value
var arr = [1, 2, 3];
var a = Arr.pop ();
alert (a);
Alert (arr);
3. Array name. unshift (insert content);
Insert data to the front and return its length
var arr = [1, 2, 3];
var a = Arr.unshift (4,5);
alert (a);
Alert (arr);
4. Array name. push (insert content);
Insert data to the last face and return its length
var arr = [1, 2, 3];
var a = Arr.push (4,5);
alert (a);
Alert (arr);
5. Array name. Splice (start index, number of deletions, data to be inserted);
var arr=[1,2,3];
var a = Arr.splice (1, 0, 4, 5,7);
alert (a);
Alert (arr);
alert (arr.length);
6. Reverse Order
Array name. reverse ();
var arr=[1,2,3];
var reverse = Arr.reverse ();
Alert (arr);
alert (reverse);
7. Array name. concat (another array): concatenation of two arrays
var arr=[1,2,3];
var a=[4,5,6];
var b=arr.concat (a);
alert (b);
8. Array name. Slice (start,end)
Returns a new array that consists of the entries from the original array that specify the starting subscript to the end subscript
Does not modify the array, it returns a sub-array. If you want to delete an element from an array, you should use the method Array.splice
()。
If there is no end, then the slice () method selects all elements from start to the end of the array.
var arr=[1,2,3,4,5];
var b=arr.slice (1,4);
alert (b);
Creation and manipulation of arrays