I'm working on a simple TypeScript task where I need to extract unique strings from a map, as discussed in this post.
Here's the code snippet I'm using:
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.includes(name));
if (!myData.includes(name)){
myData.push(name);
}
}
Even though the console output shows that each string being processed isn't already in the array, I still end up with duplicates at the end. Here's an example of the output:
## we have COW
### is property ? false
## we have COW
### is property ? false
## we have RAODN
### is property ? false
## we have COOL
### is property ? false
I've checked the TypeScript documentation, but couldn't find any reference to a 'hashset' or set for unique elements.
Is there an equivalent in TypeScript to a Set for maintaining a list of unique elements?