Alex Rivera | Logout

JavaScript associate array

Asked 2011-03-25T14:57:12.000
32

In Python I could do something like myMap = {key: [value1, value2]} and then access the value2 using myMap[key][1]

Can I do something like this in JavaScript?

Edit
Report

1 Answer

8

Yes, and the syntax is almost the same too.

var myMap = {key: ["value1", "value2"]};
alert(myMap["key"][1]); // Pops up an alert with the word "value2"

You can also use the following notation:

myMap.key[1]
answered 2011-03-25T15:01:56.720

Your Answer