JavaScript Array Length property gets the array lengths or sets the number of array elements

Source: Internet
Author: User
Tags array length javascript array

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:

    1. 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
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.