JavaScript Map values()

Definition and usage

values() The method returns an iterator object containing all values of the Map.

values() The method does not change the original Map.

Instance

Example 1

// Create a Map
const fruits = new Map([
  ["apples", 500],
  ["bananas", 300],
  ["oranges", 200]
]);
// List all values
let text = "";
for (const x of fruits.values()) {
  text += x;
}

Try it yourself

Example 2

Usage values() Method to sum values in Map:

// Create a Map
const fruits = new Map([
  ["apples", 500],
  ["bananas", 300],
  ["oranges", 200]
]);
// Sum all values
let total = 0;
for (const x of fruits.values()) {
  total += x;
}

Try it yourself

Syntax

map.values()

Parameters

None.

Return value

Type Description
Iterator An iterable object containing all values of Map.

Browser support

map.values() Is a feature of ECMAScript6 (ES6).

Starting from June 2017, all modern browsers support ES6 (JavaScript 2015):

Chrome Edge Firefox Safari Opera
Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 April 2017 June 2017 September 2016 June 2016

map.values() Not Supported in Internet Explorer.