iterate through a map code example

Example 1: java iterate through map

for (Map.Entry entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    // ...
}

Example 2: loop through map in js

const object = {'a': 1, 'b': 2, 'c' : 3};
for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}

Example 3: how to loop through a map in js

var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

for (const [key, value] of Object.entries(myMap)) {
  console.log(key, value);
}

Tags:

Misc Example