如何在JavaScript中进行关联数组/哈希

萝らか妹 提交于 2020-08-18 08:17:57

问题:

I need to store some statistics using JavaScript in a way like I'd do it in C#: 我需要使用JavaScript来存储一些统计信息,就像在C#中那样:

Dictionary<string, int> statistics;

statistics["Foo"] = 10;
statistics["Goo"] = statistics["Goo"] + 1;
statistics.Add("Zoo", 1);

Is there an Hashtable or something like Dictionary<TKey, TValue> in JavaScript? JavaScript中是否有Hashtable或类似Dictionary<TKey, TValue>类的东西?
How could I store values in such a way? 如何以这种方式存储值?


解决方案:

参考一: https://stackoom.com/question/54JS/如何在JavaScript中进行关联数组-哈希
参考二: https://oldbug.net/q/54JS/How-to-do-associative-array-hashing-in-JavaScript
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!