Javascript教程第二十二课:Javascript的数组-Array
The Array object is used to store a set of values in a single variable name. Defining Arrays
|
var myArray=new Array() |
There are two ways of adding values to an array (you can add as many values as you need to define as many variables you require).
有两种方法来添加数组值(你可以添加你所需要的值并定义你所想要的变量名称)
1:
var mycars=new Array() |
You could also pass an integer argument to control the array's size:
还可以通过引入一个整数来控制数组的大小:
var mycars=new Array(3) |
2:
var mycars=new Array("Saab","Volvo","BMW")
|
Note: If you specify numbers or true/false values inside the array then the type of variables will be numeric or Boolean instead of string.
注意:如果你在数组里指定数字或真/假值那么变量的类型将变为数字型或布尔型替换了字符串型
Accessing Arrays
访问数组
You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0.
你可以指示数组的名称和索引数字来从数组中提出一个单独的元素。索引数字从0开始。
The following code line:
正如下面的代码行:
document.write(mycars[0]) |









