Managed web hosting - A Array index delimiter ([ ]) (Delimiter)

A Array index delimiter ([ ]) (Delimiter) But in JavaScript we can at least manage this: multiArray[1][2] This is close enough that most programmers will be able to cope with it quite happily. Another alternative way to do this is to use a single dimensional array, but calculate the indices. For example to make a 5 x 5 array, you would create a single dimensional array that is 25 elements long. Then to reach the rows you use the row number and multiply the value by 5 before adding the column number to access the desired cell. You need to be careful though because if you have an ‘off-by-one’ error, it all goes wrong. Warnings: . Be aware that your script is referring to array elements starting at zero. You can get subtle ‘off-byone’ errors if you assume that the array begins at item 1. . In Netscape 2.02, the length property of an array cannot be relied on to hold the right value. . You should avoid putting spaces into associative names because it introduces a property whose name cannot be reached other than via an array index. Not all implementations will trap this error situation. A property name is an identifier and identifier names cannot contain spaces so it should throw an exception. Example code: See also: Array object, Array.length, Associativity, Multi-dimensional arrays, Off by one errors, Operator Precedence, Postfix operator, Property name

Leave a Reply