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.