JavaScript Programmer’s Reference Cross-references: (Simple web server) ECMA 262 edition 2
Friday, July 27th, 2007JavaScript Programmer’s Reference Cross-references: ECMA 262 edition 2 section 7.6 ECMA 262 edition 2 section 11.2 ECMA 262 edition 3 section 7.7 Wrox Instant JavaScript ISBN 1-861001-27-4 page 16 Wrox Instant JavaScript ISBN 1-861001-27-4 page 32 Wrox Instant JavaScript ISBN 1-861001-27-4 page 33 Array literal (Declaration) A means of creating and initializing an array at once. Availability: ECMAScript edition 3 JavaScript 1.3 JScript 5.0 Internet Explorer 5.0 Netscape 4.7 Property/method value type: Array object JavaScript syntax: -[ anElement, … ] Argument list: anElement An element to be stored in the array JavaScript version 1.2 introduces the capability of assigning values to an array as it is created and building the array without first using a constructor. Now array construction can also be nested to create multi-dimensional arrays. The result is an array containing the elements defined by the literal expression. Warnings: . Netscape 4 does not mind an extra trailing comma (as per the C language convention). To force an undefined element to be assigned to the end of the array, you must place two trailing commas. . MSIE adds an undefined element for each trailing comma. This means that MSIE creates arrays that are one item longer than Netscape does if there is a trailing comma. . Some revisions of Netscape exhibit a further problem in that a single numeric value in the square brackets is interpreted as an array length value. This is consistent with the Array() constructor but is not correct in this context. You can place a pair of trailing commas there to fix this at the expense of some wasted array items that contain undefined values. This is not a problem on all versions and may be encountered only rarely now.