iterate over map javascript code example
Example 1: 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 2: iterate map
Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
}
Example 3: iterate over map key value javascript
recipeMap.forEach((value, key) => {
console.log(`${key} costs ${value}`);
});
Example 4: 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 5: js foreach key value
Object.keys(obj).forEach(function (key) {
});
Example 6: js loop trough map
for (let key of map) {
console.log(key);
}