JavaScript Map values() method - JavaScript Tutorial

JavaScript Map values() method

BLUF: This tutorial on JavaScript Map values() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Map values() method

Understanding JavaScript Map values() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The values method of the JavaScript Map returns a new Map iterator object. This object provides access to the values of each element within the Map while preserving the order in which they were inserted.

Syntax

The values function is illustrated with the syntax below:

Example

mapObj.values()

Parameter

A new object of map iterator.

JavaScript Map values method example

In this section, we will explore the values method using a range of examples.

Example 1

Let's see a simple example of values method.

Example

<script>

var map=new Map();

map.set(1,"jQuery");

map.set(2,"AngularJS");

map.set(3,"Bootstrap");

var itr=map.values();

document.writeln(itr.next().value+"<br>");

document.writeln(itr.next().value+"<br>");

document.writeln(itr.next().value);

 </script>

Output:

Output

jQuery

AngularJS

Bootstrap

Example 2

Let's see the same example using for loop.

Example

<script>

var map=new Map();

map.set(1,"jQuery");

map.set(2,"AngularJS");

map.set(3,"Bootstrap");

var itr=map.values();

for(i=0;i<map.size;i++)

  {

document.writeln(itr.next().value+"<br>");

  }

  </script>

Output:

Output

jQuery

AngularJS

Bootstrap

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience