Availability
JavaScript 1.1, JScript 2.0; ECMAScript v1
Synopsis
array.lengthDescription
The length property of an array is always one
larger than the highest element defined in the array. For traditional
"dense" arrays that have contiguous elements and begin
with element 0, the length property specifies the
number of elements in the array.
The length property of an array is initialized
when the array is created with the Array( )
constructor method. Adding new elements to an array updates the
length, if necessary:
a = new Array( ); // a.length initialized to 0
b = new Array(10); // b.length initialized to 10
c = new Array("one", "two", "three"); // c.length initialized to 3
c[3] = "four"; // c.length updated to 4
c[10] = "blastoff"; // c.length becomes 11
You can set the value of the length property to
change the size of an array. If you set length to
be smaller than its previous value, the array is truncated and
elements at the end are lost. If you set length to
be larger than its previous value, the array becomes bigger and the
new elements added at the end of the array have the
undefined value.
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.