Example of Map in Javascript ES6

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

With ES6, we have Map where we can store key value pairs using the “set” method…

example of map

We get elements out using “get” method.  The map has a property of size to indicate the number of elements.

We can get all keys and get all values using keys() and values().  But a better way might be to iterate over all elements using for-of loop and destructuring.

More Map Methods

map methods

We can delete an element using delete() and delete all elements using clear().  The has() method will tell you if there is an element with a specific key.

More ES6 features here.