Map holds key-value pairs.
For us to start adding anything into our map we need to save an instance of the map in a variable.
const map = new Map()
Currently our map object is empty. Below I will show you the different things we can do with our map Object, and what the Big O notation is.
To ADD value into the map. O(1)(notice how I made my value into an array to push values to it later) You don’t need this if you don’t need to push.
To RETRIEVE value from map O(1)
To DELETE value from map O(1)
To get the SIZE of the map
To PUSH value to an established key-value pair
To CHECK if a key is already present
To RETURN the list of keys that have a value greater than 1
return [...map.values()].filter(m => m.length > 1)
There are a couple more methods you can use with Map but this is a good start to be able to solve more problems. I also suggest to visit the MDN Web Docs for Map in JS.
I hope this was helpful to get a clearer view on the Hash Map. I was extremely confused at the beginning because I though you have to create your own. Fortunately, JS makes it easier on us.