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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.