我需要使用JavaScript存储一些类似于C#中的统计数据:
Dictionary<string, int> statistics;
statistics["Foo"] = 10;
statistics["Goo"] = statistics["Goo"] + 1;
statistics.Add("Zoo", 1);
在JavaScript中是否有类似Hashtable
或Dictionary<TKey, TValue>
的东西?
我该如何以这种方式存储值?
我需要使用JavaScript存储一些类似于C#中的统计数据:
Dictionary<string, int> statistics;
statistics["Foo"] = 10;
statistics["Goo"] = statistics["Goo"] + 1;
statistics.Add("Zoo", 1);
在JavaScript中是否有类似Hashtable
或Dictionary<TKey, TValue>
的东西?
我该如何以这种方式存储值?
var dictionary = { Name:"Some Programmer", Age:24, Job:"Writing Programs" };
// Iterate over using keys
for (var key in dictionary) {
console.log("Key: " + key + " , " + "Value: "+ dictionary[key]);
}
// Access a key using object notation:
console.log("Her name is: " + dictionary.Name)