how to iterate through a map code example
Example 1: iterate map
Map map = ...
for (Map.Entry entry : map.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
}
Example 2: loop through map in js
var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");
for (const [key, value] of myMap.entries()) {
console.log(key, value);
}
Example 3: iterate through map
//traditional way (long)
for(map::iterator it=m.begin(); it!=m.end(); ++it)
if(it->second)cout<first<<" ";
//easy way(short) just works with c++11 or later versions
for(auto &x:m)
if(x.second)cout<
Example 4: 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);
}