Efficient syntax for populating a javascript associative array

前端 未结 2 1889
挽巷
挽巷 2020-12-29 06:41

I have an autocomplete text box that users can type an item code into and need to find out what the id number of that item code is in javascript.

An associative arra

2条回答
  •  情深已故
    2020-12-29 07:14

    Try using Object Literal notation to specify your lookup like this:

    var itemIds = {
        "item1" : 15,
        "item2" : 40
        ...
    };
    

    Access should still work like this:

    var item1Value = itemIds["item1"];
    

提交回复
热议问题