Length Property (Array)

Source: Internet
Author: User
Tags array array definition object

Returns an integer value that is 1 larger than the subscript of the highest bit element defined in the array.

numVar = arrayObj.length

Parameters

Numvar

Required option. Any number.

Arrayobj

Required option. Any Array object.

Description

Because the elements in an array are not necessarily contiguous, the length property is also not necessarily equal to the number of elements in the array. For example, in the following array definition, the My_array.length contains 7 instead of 2:

var my_array = new Array( );my_array[0] = "Test";my_array[6] = "Another Test";

If the length property is given a value that is smaller than the original value, the array is truncated and all elements of the array subscript equal to or greater than the new value of the length property are lost.

If the length property is given a value larger than the original, the array is extended and all new elements are assigned to undefined.

The following example illustrates the use of the length property:

function LengthDemo(){   var a;   a = new Array(0,1,2,3,4);   return(a.length);}

Requirements

Version 2

Please see

Length Property (Function) | Length Property (String)

Apply to: Array Object



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.