ben657 ben657 - 1 year ago 109
TypeScript Question

TypeScript, Looping through a dictionary

In my code, I have a couple of dictionaries (as suggested here) which is String indexed. Due to this being a bit of an improvised type, I was wondering if there any suggestions on how I would be able to loop through each key (or value, all I need the keys for anyway). Any help appreciated!

myDictionary: { [index: string]: any; } = {};

Ian Ian
Answer Source

To loop over the key/values, use a for in loop:

for (var key in myDictionary) {
    var value = myDictionary[key];
    // Use `key` and `value`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download