Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
numVar = arrayObj.length
Required. Any number.
length property is not necessarily the number of elements in the array. For example, in the following array definition,
my_array.length contains 7, not 2:
var my_array = new Array( ); my_array = "Test"; my_array = "Another Test";
If you make the
length property smaller than its previous value, the array is truncated, and any elements with array indexes equal to or greater than the new value of the
length property are lost.
If you make the length property larger than its previous value, the array is expanded, and any new elements created have the value
The following example illustrates the use of the
var a; a = new Array(0,1,2,3,4); document.write(a.length); // Output // 5
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.
Starting with Internet Explorer 9 Standards mode, trailing commas included in the initialization of an Array are handled differently.