The entries() method returns an iterator object containing the [key, value] pairs in a Map.
// List all entries let text = “”; for (const x of fruits.entries()) { text += x; } |
The keys() method gives an iterator object that holds the keys of a Map.
// List all keys let text = “”; for (const x of fruits.keys()) { text += x; } |
The values() method returns an iterator object that contains the values in a Map.
// List all values let text = “”; for (const x of fruits.values()) { text += x; } |
You can use the values()
method to calculate the sum of the values in a Map.
// Sum all values let total = 0; for (const x of fruits.values()) { total += x; } |