JavaScript Map

JavaScript map object is used to store the elements as key-value pair. All the operation like search, add, update, delete are done using key.

Syntax:

new Map([iterable])

Parameters: iterable: It represents the object whose elements are in the form of key-value pair.

Note: Map object can not contain the duplicate keys but can contain duplicate values.

JavaScript Map Methods:

clear() Use: To remove all the elements from a Map object.

delete() Use: To delete the specified element from a Map object.

entries() Use: To return an object of Map iterator that contains the key-value pair for each element.

forEach() Use: To execute the specified function once for each key/value pair.

get() Use: To return the value of specified key.

has() Use: To indicate whether the map object contains the specified key element.

keys() Use: To return an object of Map iterator that contains the keys for each element.

set() Use: To add or update the key-value pairs to Map object.

values() Use: To return an object of Map iterator that contains the values for each element.

Please follow and like us:
Content Protection by DMCA.com