Javatpoint Logo
Javatpoint Logo

JavaScript Map Object

The JavaScript Map object is used to map keys to values. It stores each element as key-value pair. It operates the elements such as search, update and delete on the basis of specified key.

Syntax

Parameter

iterable - It represents an array and other iterable object whose elements are in the form of key-value pair.

Points to remember

  • A map object cannot contain the duplicate keys.
  • A map object can contain the duplicate values.
  • The key and value can be of any type (allows both object and primitive values).
  • A map object iterates its elements in insertion order.

JavaScript Map Methods

Let's see the list of JavaScript map methods with their description.

Methods Description
clear() It removes all the elements from a Map object.
delete() It deletes the specified element from a Map object.
entries() It returns an object of Map iterator that contains the key-value pair for each element.
forEach() It executes the specified function once for each key/value pair.
get() It returns the value of specified key.
has() It indicates whether the map object contains the specified key element.
keys() It returns an object of Map iterator that contains the keys for each element.
set() It adds or updates the key-value pairs to Map object.
values() It returns an object of Map iterator that contains the values for each element.

Next TopicJavaScript Map




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA