Availability: |
| ||||||||
JavaScript syntax: | - | myArray = Array | |||||||
- | myArray = myVBArray.toArray() | ||||||||
- | myArray = new Array() | ||||||||
- | myArray = new Array(aLength) | ||||||||
- | myArray = new Array(anItem1, anItem2, anItem3, ...) | ||||||||
Argument list: | aLength | An optional initial length to set the array to. | |||||||
anItemN | A variable number of initial elements to insert into the array. | ||||||||
Object properties: | constructor, index, input, length, prototype | ||||||||
Object methods: | concat(), join(), pop(), push(), reverse(), shift(), slice(), sort(), splice(), toLocaleString(), toSource(), toString(), unshift(), valueOf() |
An array is basically an indexed collection of references to other objects or values.
In JavaScript version 1.0, arrays were simple objects and had limited functionality, scarcely enough really to be called arrays. Some commentators argue that the functionality was so limited that they should be flagged as available from version 1.1 of JavaScript only. They were usually simulated by creating an instance of the Object object and using its named properties as if the object was an array.
Much additional functionality was added for JavaScript version 1.1. JavaScript version 1.0 lacked the constructors and arrays had no special methods available. The ECMA standard enhances the functionality and Netscape 4 provides additional functionality.
An instance of the class "Array" is created by using the new operator on the Array() constructor. At JavaScript version 1.2, Arrays can be created with an Array literal as well. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms.
All properties and methods of the prototype are available as if they were part of the instance.
Note that the index and input properties are available only for Arrays that are produced as the result of a RegExp match. They are not generally available in Arrays or Collections.
An array is a collection of properties owned by an object and which can be accessed by name or by index position in the array. Because they are collected together and accessible as a set, they may be sorted into order of the array.
Array objects give special treatment to property names, which are numeric values. These are used as an index value and will affect the value of the length property. The length supported depends on the platform, but is usually based on a 32 bit integer being used for addressing. That limits the range to 4 Billion array elements.
Array objects implement the Put() internal function slightly differently to non-array based objects.
The prototype for the Array prototype object is the Object prototype object.
In C language, an array is referred to as an aggregate type since it is made from a collection or aggregate of individual members.
Although arrays were partially supported prior to JavaScript version 1.1, the support was not reliably or completely implemented. There was no way for the script developer to create and modify the arrays. Netscape 2 lacks any realistic Array support even though Array objects were returned by some object properties.
The WebTV set top box limits the extent of the Array objects to contain only 32768 elements instead of the 4 Billion or so that is defined as the normal maximum. This is because WebTV uses 16 bit integers for addressing arrays rather than 32 bit integers.
<SCRIPT>// Array object demonstration var weekly_summary = new Array(7); weekly_summary[1] = 10; weekly_summary[2] = 25; var day_names = new Array("Su","Mo","Tu","We","Th","Fr","Sa"); for(var i=0; i<7; i++) { document.write("Summary for day ("); document.write(day_names[i]); document.write(") = "); document.write(weekly_summary[i]); document.write("<BR>"); } </SCRIPT>
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
constructor | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
index | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
input | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
length | 1.0 ![]() | 3.0 ![]() | 2.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly |
prototype | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | ![]() | ![]() | 2 ![]() | ![]() | ![]() | ![]() | ReadOnly, DontDelete, DontEnum. |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
concat() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
join() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
pop() | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
push() | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
reverse() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | - |
shift() | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
slice() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
sort() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
splice() | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
toLocaleString() | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
toSource() | 1.3 ![]() | 3.0 ![]() | 4.06 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
toString() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | 3.0 ![]() | 2.0 ![]() | 2 ![]() | ![]() | ![]() | ![]() | ![]() |
unshift() | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
valueOf() | 1.1 ![]() | 3.0 ![]() | 3.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
ECMA 262 edition 2 - section - 8.6.2.2
ECMA 262 edition 2 - section - 15.4
ECMA 262 edition 3 - section - 8.6.2.2
ECMA 262 edition 3 - section - 15.4
Wrox Instant JavaScript - page - 15
Prev | Home | Next |
Array literal | Up | Array() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |