JavaScript Maps
A Map holds key-value pairs where the keys can be any datatype. A Map remembers the original insertion order of the keys.
Creating a Map
You can create a Map and add elements with the set() method:
javascript
const fruits = new Map();
fruits.set("apples", 500);
fruits.set("bananas", 300);Map Methods
set()- Sets the value for a key in a Map.get()- Gets the value for a key in a Map.delete()- Removes a Map element specified by the key.has()- Returns true if a key exists in a Map.forEach()- Calls a function for each key/value pair.entries()- Returns an iterator with the [key, value] pairs.
Test Yourself with an Exercise
Which method is used to add a new key-value pair to a Map?