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