how to iterate through map javascript 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: use map to loop through an array
let squares = [1,2,3,4].map(function (val) {
return val * val;
});
// squares will be equal to [1, 4, 9, 16]