user1019182 user1019182 - 3 years ago 591
TypeScript Question

How to iterate over a Set in typescript?

How do you iterate over a set in typescript? for..of does not work:

'Set<string>' is not an array type or a string type

is not acceptable, because it hides
. I'd prefer not to do a while loop in a try catch block. What am I missing? It can't it possibly so clumsy as to require try {while} catch {}.

Answer Source

@SnareChops was mostly correct:

    // do something with "this"
}, **this**);

This works.

I'm guessing:

for(item of mySet.values()){

Would work if I weren't working with es-shim stuff which is messing everything up for me. But the shim stuff is prescribed by the Angular 2 crew so ¯_(ツ)_/¯

The only other thing that worked was:

for (var item of Arrays.from(set.values())) {

or something like that, which is just terrible.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download