Sunday, May 19, 2024
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 32039  / 14 Years ago, thu, may 27, 2010, 12:00:00

I want to define an associative array like this



var theVar = [
{ 100, [0, 1, 2] },
{ 101, [3, 4, 5] }
]


Essentially I want to be able to access an array of three numbers by specifying the custom index.



However, no matter what I try I cannot make it work.



I know I can define it as:



theVar[100] = [0, 1, 2];
theVar[101] = [1, 2, 3];


But I am setting this somewhere else and I'd prefer to be able to set it in a single statement.


More From » web-applications

 Answers
24
theVar = {
100: [0, 1, 2],
101: [3, 4, 5]
}


might do the trick. You can then access using theVar[101] (or theVar[101] for that matter).



(As var is also a keyword in JavaScript, using it as a variable name is very likely to cause problems.)


[#96657] Tuesday, May 25, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanap

Total Points: 413
Total Questions: 82
Total Answers: 99

Location: South Georgia
Member since Mon, Oct 19, 2020
4 Years ago
;