JScript uses Arrays

Source: Internet
Author: User

 

Array subscript
Arrays in JScript are sparse. That is to say, if an array has three elements numbered 0, 1, and 2, you can create element 50 without worrying about parameters from 3 to 49. If the array has an automatic length variable,

(See internal object for automatic monitoring of array length). The length variable is set to 51, not 4. Of course, you can create an array with no gaps between the numbers of each element, but it is not necessary to do so.

In JScript, objects and arrays are almost the same. The two main differences are that the object does not have the automatic Length attribute, but the array does not have the attribute and method of the object.

Array addressing
Use square brackets "[]" to address arrays. Square brackets contain a value or an expression whose value is an integer. The following example assumes that the entrynum variable has been defined elsewhere in the script and has been assigned a value.

Thelisting = addressbook [entrynum];
Thefirstline = thelisting [1];
Use an object as an associated array
Generally, the dot operator "." is used to access the properties of an object. For example,

Myobject. aproperty
Here, the property name is an identifier. You can also use the index operator "[]" to access object attributes. Here, the object is treated as an associated array. An associated array is a data structure that dynamically matches any data value with any string.

Associated. For example,

Myobject ["aproperty"] // same as above.
Although index operators are more used to access array elements, when used for objects, indexes are always attribute names represented by string characters.

Note the important differences between the two methods for accessing object attributes.

Processing of attribute names using operator property names
The dot "." identifier cannot be used as data processing.
Index "[]" string text can be processed as data

This difference is useful when you do not know the attribute name before running (for example, when constructing an object based on user input ). To extract all attributes from an associated array, you must use... In loop.

 

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.