M
mark4asp
Suppose I wanted to create an array that was associative in 2
dimensions. The rows are associated with numbers. The columns with
words.
For instance for 3 columns. This array will have 20 rows of three
columns and the words that I want to associate with the columns are
'Small', 'Medium' and 'Large'. All the array elements are positive
integers. What's the easiest way to do this?
The first 3 columns are shown below for the array that is associative
by row:
sizes = {1:[16, 17, 19], 2:[16, 18, 23], 3:[16, 18, 25] }
This is how I can do it for columns:
function sizes(Small, Medium, Large) {
this.Small = Small;
this.Medium = Medium
this.Large = Large;
}
r1 = new sizes(16, 19, 17);
r2 = new sizes(16, 23, 18);
r3 = new sizes(16, 25, 18);
The problem with that is that the rows are now indexed via a
zero-based index instead of the code I wanted to use (as in the first
definition of sizes above) - accessed via an index starting at 1.
Is there a way I could create an associative array to refer to data
item 25 in the array as:
sizes[3][Large]
PS: As always this is an illustrative example.
dimensions. The rows are associated with numbers. The columns with
words.
For instance for 3 columns. This array will have 20 rows of three
columns and the words that I want to associate with the columns are
'Small', 'Medium' and 'Large'. All the array elements are positive
integers. What's the easiest way to do this?
The first 3 columns are shown below for the array that is associative
by row:
sizes = {1:[16, 17, 19], 2:[16, 18, 23], 3:[16, 18, 25] }
This is how I can do it for columns:
function sizes(Small, Medium, Large) {
this.Small = Small;
this.Medium = Medium
this.Large = Large;
}
r1 = new sizes(16, 19, 17);
r2 = new sizes(16, 23, 18);
r3 = new sizes(16, 25, 18);
The problem with that is that the rows are now indexed via a
zero-based index instead of the code I wanted to use (as in the first
definition of sizes above) - accessed via an index starting at 1.
Is there a way I could create an associative array to refer to data
item 25 in the array as:
sizes[3][Large]
PS: As always this is an illustrative example.