javascript Array对象介绍

时间:2010-04-12 12:27:21  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: 创建源The Array object constructor:  new Array(arrayLength);new Array(element0, element1, ..., elementN); 参数 arrayLength(Optional) The initial length of the array. You can access this value using the length 属性....
  正文:

Array

Represents an array of elements.

Core object
实现版本Navigator 3.0, LiveWire 1.0

 

创建源

The Array object constructor:

 

new Array(arrayLength);
new Array(element0, element1, ..., elementN);

参数

 

arrayLength(Optional) The initial length of the array. You can access this value using the length 属性.
elementN(Optional) A list of values for the array's elements. When this form is specified, the array is initialized with the specified values as its elements, and the array's length 属性 is set to the number of arguments.

 

描述

In Navigator 3.0, you can specify an initial length when you create the array. The following code creates an array of five elements:

 

billingMethod = new Array(5) When you create an array, all of its elements are initially null. The following code creates an array of 25 elements, then assigns values to the first three elements:

musicTypes = new Array(25)
musicTypes[0] = "R&B"
musicTypes[1] = "Blues"
musicTypes[2] = "Jazz" However, in Navigator 4.0, if you specify LANGUAGE="JavaScript1.2" in the <SCRIPT> tag, using new Array(1) creates a new array with a[0]=1.

An array's length increases if you assign a value to an element higher than the current length of the array. The following code creates an array of length 0, then assigns a value to element 99. This changes the length of the array to 100.

colors = new Array()
colors[99] = "midnightblue" You can construct a dense array of two or more elements starting with index 0 if you define initial values for all elements. A dense array is one in which each element has a value. The following code creates a dense array with three elements:

myArray = new Array("Hello", myVar, 3.14159) In Navigator 2.0, you must index an array by its ordinal number, for example document.forms[0]. In Navigator 3.0 and later, you can index an array by either its ordinal number or by its name (if defined). For example, assume you define the following array:

myArray = new Array("Wind","Rain","Fire") You can then refer to the first element of the array as myArray[0] or myArray["Wind"].

In Navigator 4.0, the result of a match between a regular expression and a string can create an array. This array has properties and elements that provide information about the match. An array is the return value of RegExp.exec, String.match, and String.replace. To help explain these properties and elements, look at the following example and then refer to the 表 below:

<SCRIPT LANGUAGE="JavaScript1.2">
//Match one d followed by one or more b's followed by one d
//Remember matched b's and the following d
//Ignore case myRe=/d(b+)(d)/i;
myArray = myRe.exec("cdbBdbsbz"); </SCRIPT> The properties and elements returned from this match are as follows:

javascript Array对象介绍》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/JavaScript/13594.html

 1/9    1 2 3 4 5 6 下一页 尾页


关键字:

关于《javascript Array对象介绍》文章的评论

Property/Element 描述 Example
inputA 只读 属性 that reflects the original string against which the regular expression was matched.cdbBdbsbz
indexA 只读 属性 that is the zero-based index of the match in the string.1
[0]A 只读 element that specifies the last matched characters.dbBd
站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td