Ok. I guess num represents the value and not the key. Is it also possible to access the key with this apporach? I need the key and the value in the loop.
There is a solution that isn’t that elegant but before I come to that, let me explain what is happening here. The blocks generate the following code
myMap = {'key0': 'one', 'key1': 'two', 'key2': 'three'};
for (var num_index in myMap) {
num = myMap[num_index];
logger.info(num);
}
So, you can see, it is actually iterating via an index because it perceives it as a index as usually it would use a list-array. However it works, because in that case the index is the key and it is used to lookup the value in the map.
Let’s rename the variable to key and magically the block will create a code that generates a key and a key_index variable
… but it does work. For the sake of completeness there is even another less elegant version where we create our own loop … I leave to the reader to find out why that one works (have a look into the generated code )