×
Understanding Map object in JavaScript


Understanding Map object in JavaScript

October 23, 2019

Map

  • Hold key-value pairs
  • Remember the order of insertion.
  • Can have objects or primitive values as key or value.

Map is a JavaScript object which can hold key-value pairs  and remember the order of insertion. Maps inherit from  Map.prototype.

Map.prototype.constructor returns the constructor function that created an instance’s prototype.

A new Map is created using the map constructor in the following way.

We can set key-value pairs using the set method


You can see here that  Map remembers the order of insertion.  Maps can have objects or primitive values as key or value. For example, see the following map which has an object as key and object value.

Here we set object key-value pairs using the set method and retrieve it using the get method.

 

Now get the object value belonging to object key using get method

 

Read more on Map.prototype hereMap

One Comment

  • arun kr October 28, 2019 at 6:38 am

    great tutorial, akr

Leave a Reply

Your email address will not be published. Required fields are marked *