ang*_*yip 7 typescript angular
我试图在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中是否有相同的东西?即一系列独特元素
Mar*_*cel 22
它存在!
mySet: Set<string> = new Set<string>();
Run Code Online (Sandbox Code Playgroud)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set