我需要使用JavaScript存储一些统计信息,就像我在C#中这样做:
Dictionary<string, int> statistics;
statistics["Foo"] = 10;
statistics["Goo"] = statistics["Goo"] + 1;
statistics.Add("Zoo", 1);
Run Code Online (Sandbox Code Playgroud)
JavaScript中是否有Hashtable类似的东西Dictionary<TKey, TValue>?
我怎么能以这种方式存储价值?
我试图在TypeScript中做一些非常基本的事情.在解析本文中引用的地图时获取唯一字符串列表.
这是我试图做的事情:
let myData = new Array<string>();
for (let myObj of this.getAllData()) {
let name = myObj.name;
console.log("## we have " + name);
console.log("### is property ? " + myData.hasOwnProperty(name));
if (!myData.hasOwnProperty(name)){
myData.push(name);
}
}
Run Code Online (Sandbox Code Playgroud)
对于任何字符串,我的打印输出将始终评估为false,重复或不重复.这是一些示例输出:
## we have COW
### is property ? false
## we have COW
### is property ? false
## we have RAODN
### is property ? false
## we have COOL
### is property ? false
Run Code Online (Sandbox Code Playgroud)
但是,当该过程完成时,我的列表包含重复项.我试过看过这个文档,但是没有提到'hashset'或者一般的任何集合.
Set的TypeScript中是否有相同的东西?即一系列独特元素