Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Map.entries()

The entries() method returns an iterator object containing the [key, value] pairs in a Map.

Example

// List all entries
let text = “”;
for (const x of fruits.entries()) {
  text += x;
}

Map.keys()

The keys() method gives an iterator object that holds the keys of a Map.

Example

// List all keys
let text = “”;
for (const x of fruits.keys()) {
  text += x;
}

Map.values()

The values() method returns an iterator object that contains the values in a Map.

Example

// 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.

Example

// Sum all values
let total = 0;
for (const x of fruits.values()) {
  total += x;
}