How to create an associative array in JavaScript literal notation

前端 未结 6 763
再見小時候
再見小時候 2021-01-30 16:39

I understand that there are no associative arrays in JavaScript, only objects.

However I can create an array with string keys using bracket

6条回答
  •  半阙折子戏
    2021-01-30 17:20

    You want to use an object in this case

    var myObject = {'a' : 200, 'b' : 300 };
    

    This answer links to a more in-depth explanation: How to do associative array/hashing in JavaScript

提交回复
热议问题