One: The role of the array object is to use a separate variable name to store a series of values
1: Create an array
Create an array, assign values to it, and output the values.
2: for...In statement
loop through elements in an array
3:join
a string consisting of the elements of the array
4: literal array (sort)
Sort an array literally
5: array of numbers
Sort an array numerically
Two: define an array
1: Array objects are used to store a series of values in separate variables
2: The assignment method of the array :
keyword new
(1) You can add as many values as you want, just as you can define as many variables as you like
var myArray=new Array()
(2) Use an integer argument to control the capacity of the array
var myArray=new Array(3)
mycars[0]="saab"
mycars[1]="volvo"
mycars[2]="BMW"
3: Specify a numerical or logical value
Specify a numeric or logical value within an array, then the variable type baby is a numeric or boolean variable, not a character variable.
Three: access the array
Each specific element can be accessed by specifying the array name and index number
Four: Modify the value in the existing array
Modify the value in the existing array, orderly add a new value to the specified subscript.
Five: Objects in an array
There can be different objects in an array, all javaScript variables are objects.
Array elements are objects. Functions are objects, so there can be different types of variables in the array, which can contain object elements, functions, and arrays.
Six: Array methods and properties
Predetermining properties and methods using array objects
var x=myCare.length //the number of elements in myCars
var y=mycars.indexOf("Volvo") //"Volvo" is worth the index value
Two-dimensional array
data type array name[integer constant expression][integer constant expression]={initialization data};
The initial value of each array element is given in { }, and each initial value is separated by a comma. Assign the initial values in { } to each array element in turn.
Two-dimensional array definition and sorting method
example:
//Define and initialize
var treeCol=new Array();
for(var i=0;i<2;i++){
treeCol[i]=new Array();
for(var j=0;j<2;j++){
treeCol[i][j]=1;
}
}
//赋值
treeCol[0][0]="organtreeDisplay";
treeCol[0][1]="partyunit";
treeCol[1][0]="jiguantreeDisplay";
treeCol[1][1]="placetree";
What is an array:
Organize several variables with the same data type in an ordered form,
For the convenience of program processing, the collection of these data elements is an array
The difference between one-dimensional arrays and two-dimensional arrays
One-dimensional arrays represent a row or a point; two-dimensional arrays represent multiple rows or.