JavaScript Map values() Method Tutorial

In this section, we will learn what the values() method is and how to use it in JavaScript.

What is JavaScript Map values() Method?

We use the `values()` method to get an iterator object that contains all the values of the target map object (The one that this method is invoked on).

Note: the iterator object is explained in later sections.

We can then use this method and the for-of statement to loop through all the values of the target map object.

JavaScript Map values() Method Syntax:

values()

values() Function Parameters:

The method does not take an argument.

values() Function Return Value:

The return value of this method is an iterator object that contains all the values of the target map object.

Example: using Map values() method in JavaScript

const map = new Map();
 map.set("John","222-22222222");
 map.set(22 , 2000);
 map.set(true, false); 
 map.set("Jack", "333-3234232");
 
 for (const value of map.values()){
   console.log(value);
 }   

Output:

222-22222222

2000

false

 333-3234232
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies