JavaScript Array Length Property
The length property of the JavaScript array can return or set the number of elements in the group, with the following syntax:
Array_object.length
Use the Length property to get the number of elements
<script language= "JavaScript" >varnew Array (' A ', 10.5,true' array length ' + Array_1.length); </script>
To run the example, the popup window output: Array length 3
Let's look at this particular example:
<script language= "JavaScript" >varnew Array (' A ', 10.5,true); array_1[5] = ' B '+ "<br/>"' array length ' + array_1.length); </script>
To run the example, output:
This example illustrates:
- When an array element is incremented with an array subscript, an empty element of undefined appears in the middle if the last element is not incremented next to it
- The empty elements of the undefined are counted in the number of array elements, that is, the value of length is always greater than the maximum subscript 1 (subscript starting from 0)
Set the number of array elements with the length property
The length property can also be used to set the number of elements in an array, as shown in the following example:
<script language= "JavaScript" >varnew Array (' A ', 10.5,true= 6+ " <br/> "' array length ' + array_1.length); </script>
To run the example, output:
Reference reading
JavaScript Array Length property gets the array lengths or sets the number of array elements