Is there a dictionary implementation in JavaScript?

前端 未结 10 2025
萌比男神i
萌比男神i 2020-12-12 22:04

How can I implement an array with an indexer in JavaScript? Is there something like a dictionary in .Net?

10条回答
  •  醉梦人生
    2020-12-12 22:33

    Technically not, but you can use a regular JavaScript object like a dictionary:

    var a = {"a":"wohoo", 2:"hello2", "d":"hello"};
    alert(a["a"]);
    alert(a[2]);
    alert(a["d"]);
    

提交回复
热议问题