I want to iterate over all values of a map. I know it's possible to iterate over all keys. But is it possible to iterate directly over the values?
var map = { key1 : 'value1', key2 : 'value2' }
for (var key in map) { ...} // iterates over keys
This question is related to
javascript
dictionary
It's not a map. It's simply an Object
.
Edit: below code is worse than OP's, as Amit pointed out in comments.
You can "iterate over the values" by actually iterating over the keys with:
var value;
Object.keys(map).forEach(function(key) {
value = map[key];
console.log(value);
});