Javascript教程第二十二课:Javascript的数组-Array

The Array object is used to store a set of values in a single variable name.
阵列(数组)对象用来在一单独的变量名称内存储一系列值。

Defining Arrays
定义数组

The Array object is used to store a set of values in a single variable name.
数组对象被用来存储值(在单一的变量名称中)

We define an Array object with the new keyword. The following code line defines an Array object called myArray:
我们通过新的关键字来定义一个数组对象。下面的代码行定义了称为myArry的数组对象:

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()
mycars[0]="Saab"
mycars[1]="Volvo"
mycars[2]="BMW"

You could also pass an integer argument to control the array's size:
还可以通过引入一个整数来控制数组的大小:

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 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])
七种就比一种好,减得就是快,神七减肥冲剂
140.0元
Copyright ?2005-2008 All rights reserved. www.17zixue8.com 版权所有    赣ICP备07501614号        完美兵团会员待遇说明    站主QQ:335759285