'map.values(); returns weird empty "Map Iterator { }" with no values [closed]
Solution 1:[1]
Whatever the tutorial claims, the values method of a Map instance does not return an array, but an iterator.
You need to consume that iterator to get the actual values:
let mymap = new Map([[1, "a"], [2, "b"], [3, "c"]]);
console.log(mymap.values()); // Wrong: above values are not displayed
console.log(Array.from(mymap.values())); // Create array, or
console.log(...mymap.values()); // Spread as arguments
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | trincot |
