JavaScript associate array

前端 未结 5 2034
栀梦
栀梦 2020-12-15 03:46

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

Can I do som

5条回答
  •  一向
    一向 (楼主)
    2020-12-15 04:07

    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]
    

提交回复
热议问题