The length property can set or return the number of elements in the array.
Grammar:
Arrayobject.length
The length property of an array is always 1 larger than the subscript of the last element defined in the array. For regular arrays that have continuous elements and begin with element 0, the attribute length declares the number of elements in the array.
The length property of an array is initialized when an array is created with the constructor array (). When you add a new element to an array, the value of length is updated if necessary.
Set the Length property to change the size of the array. If you set a value that is smaller than its current value, the array is truncated and the elements at its tail are lost. If the value is set larger than its current value, the array will grow, and the new elements are added to the end of the array, their values are undefined.
Example:
<script type= "Text/javascript" >var arr = new Array (3) arr[0] = "John" arr[1] = "Andy" arr[2] = "Wendy" document.write (" Original Length: "+ arr.length) document.write (" <br/> ") arr.length=5document.write (" New Length: "+ arr.length) </script>
Print:
Original Length:3
New Length:5
JavaScript Array Object Length property