Iterate through keys of a Map

I'm looking for a way to get all the keys (column names in this case) and values from ScriptColumnData.columns (a map).

The documentation says: "The keys in a map can be enumerated, and are automatically kept sorted."
But I actually see no way at all to enumerate over the keys or map itself, not by an integer based index nor by some kind of collection of keys provided by the map.

With regular js-objects you can do something like this to iterate over the keys and get through to the actual value.

for(key in object){ DOpus.Output("Key: " + key + " - Value: " + object[key]); }

Something like that is what I had in mind with the map of columns (for some general approach on caching column data).

I have several scripts providing multiple columns, for which it really takes a long time to fetch all the data on a lister refresh e.g.
When script columns and lables are combined, time even doubles up, as the label-system will query all the columns again.

Thanks! o)

In JScript you'd need to use an Enumerator.

Uhh, the Enumerator? Ok, I see and.. it works!
Thank you Jon! o))

For others, also searching on how to do it:

var colEnum = new Enumerator(data.columns);
for (;!colEnum.atEnd(); colEnum.moveNext()){
    var col = colEnum.item();
    DOpus.Output("ColumnName: " + col);
}
1 Like

Could we add this code to this page?
https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Map.htm

Added an example in both languages for the next update.

1 Like