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