JavaScript Map entries() method - JavaScript Tutorial

JavaScript Map entries() method

BLUF: This tutorial on JavaScript Map entries() 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 entries() method

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

The entries method of the JavaScript Map object produces a new map iterator. This iterator provides the key-value pairs corresponding to each element within the map. It preserves the order in which the elements were inserted.

Syntax

The entries function can be expressed using the syntax below:

Example

mapObj.entries()

Return Value

A new object of map iterator.

JavaScript Map entries method example

In this section, we will explore the entries method by examining multiple examples.

Example 1

Let's see a simple example of entries method.

Example

<script>

var map=new Map();

map.set(1,"jQuery");

map.set(2,"AngularJS");

map.set(3,"Bootstrap");



var itr=map.entries();

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

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

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

  </script>

Output:

Output

1,jQuery

2,AngularJS

3,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.entries();

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

  {

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

  }

  </script>

Output:

Output

1,jQuery

2,AngularJS

3,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