Five. Addition and deletion of array elements
the simplest way to add an array element: Assign a value to a new index
a = [];//Start is an empty array
A[0] = "one";//add elements to it;
You can also use the push () method to add one or more elements to the end of the array:
a = [];//Start is an empty array
A.push ("one");//Add an element at the end of a = ["a"]
A.push ("Two", "three");//Continue adding two elements a = ["One", "two", "three"]
push () increments the element at the end of the array, the Unshift () method inserts the element at the header of the array, and moves the other elements to a higher index in turn.
Deleting an array element uses the delete operator just as you would delete an object property:
A = [n/a];
Delete a [1]; A does not have an element in the position of index 1, but the length remains the 3,delete operator and does not affect array lengths
Deleting an array element is similar to assigning a undefined value (with subtle differences), and it is important to note that using delete on an array does not modify the length property of the arrays.
It also does not move the element from the high index to fill the whitespace left by the deleted attribute (the Shift () method will). If you delete an element from an array, it becomes a sparse array.
Six. Array traversal
Using a For loop is the most common way to iterate over an array element:
Seven. Multidimensional arrays
JS does not support a true multidimensional array, but it can be approximated by an array of arrays. Access the elements in an array of arrays, as long as you use the [] operator two times.
Create a multidimensional array
var table = new Array (10)//table has 10 rows
for (var i = 0; i < table.length; i++)
table[i] = new Array (10); Each row has 10 columns
Initializing an array
for (var row = 0; Row < Table.length; row++) {
for (col = 0; col < table[row].length; col++) {
Table[row][col] = row * COL;
}
}
Use multidimensional arrays to calculate (query) 5*7
var product = table[5][7]; 35
javascript--Array (ii)