How to Get a Key-Value Pair From a Map in JavaScript
In this lesson, we will see how to get a key-value pair from a map in JavaScript, sometimes we want to log each key-value pair of a given map in JavaScript so how can we do that?
The forEach() method
To do that we can use the forEach() method that returns each key with the value.
const myMap = new Map([['name','john'],['age',22],['city','london']]);
myMap.forEach((value,key) => console.log(key,value));
//name john
//age 22
//city london