In JavaScript, you can use the keyword new to create an array object, and the syntax format is "var array name=new Array()". Array objects are used to store a series of values in separate variable names.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Array objects are used to store a series of values in separate variable names.
We use the keyword new to create an array object. The following code defines an array object named myArray:
var myArray=new Array()
There are two ways to assign values to an array (you can add as many values as you want, just like you can define as many variables as you need ).
1,
var mycars=new Array()mycars[0]="Saab" mycars[1]="Volvo" mycars[2]="BMW"
You can also use an integer independent variable to control the capacity of the array:
var mycars=new Array(3)mycars[0]="Saab" mycars[1]="Volvo" mycars[2]="BMW"
2,
var mycars=new Array("Saab","Volvo","BMW")
Note: If you need to If a numerical or logical value is specified in the array, the variable type should be a numerical variable or a Boolean variable, not a character variable.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to define an object array in JavaScript. For more information, please follow other related articles on the PHP Chinese website!