Use the JavaScript map values() method to get the value for each element in the object. This method returns a new iterator object that contains the values for each element in the Map object in insertion order.
obj.values()
JavaScript map values
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script >
const mapObj = new Map();
mapObj.set('0', 'foo');
mapObj.set(1, 'bar');
const iterator = mapObj.values();
console.log(iterator)
console.log(iterator.next().value);
console.log(iterator.next().value);
</script>
</body>
</html>
Output:
Another example using for loop
<script >
const obj = new Map();
obj.set('0', 'foo');
obj.set(1, 'bar');
var itr=obj.values();
for(i=0; i<obj.size; i++)
{
console.log(itr.next().value)
}
</script>
Do comment if you have any doubts or suggestions on this Js map method topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version