Map
Overview
The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
For more information see: Map (MDN).
Properties Summarized
Methods Summarized
Type | Name | Summary |
---|---|---|
void | The clear() method removes all elements from a Map object. | |
The delete() method removes the specified element from a Map object by key. | ||
The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Map object in insertion order. | ||
void | The forEach() method executes a provided function once for each value in the Map object, in insertion order. | |
The get() method returns a specified element from a Map object. | ||
The has() method returns a boolean indicating whether an element with the specified key exists in a Map object or not. | ||
The keys() method returns a new iterator object that contains the keys for each element in the Map object in insertion order. | ||
The set() method adds or updates an entry in a Map object with a specified key and a value. | ||
The values() method returns a new iterator object that contains the values for each element in the Map object in insertion order. |
Properties Detailed
size
The size accessor property returns the number of elements in a Map object.
Type Number
Sample
Methods Detailed
clear()
The clear() method removes all elements from a Map object.
Returns: void
Sample
delete(key)
The delete() method removes the specified element from a Map object by key.
Parameters
Object key ;
Returns: Boolean
Sample
entries()
The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Map object in insertion order. In this particular case, this iterator object is also an iterable, so the for-of loop can be used..
Returns: Iterator the iterator that can be used in for of loops
Sample
forEach(callback, thisArgument)
The forEach() method executes a provided function once for each value in the Map object, in insertion order.
Parameters
Returns: void
Sample
get(key)
The get() method returns a specified element from a Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map object.
Parameters
Object key ;
Returns: Object
Sample
has(key)
The has() method returns a boolean indicating whether an element with the specified key exists in a Map object or not.
Parameters
Object key ;
Returns: Boolean
Sample
keys()
The keys() method returns a new iterator object that contains the keys for each element in the Map object in insertion order. In this particular case, this iterator object is also an iterable, so a for...of loop can be used.
Returns: Iterator the iterator that can be used in for of loops
Sample
set(key, value)
The set() method adds or updates an entry in a Map object with a specified key and a value.
Parameters
Returns: Map
Sample
values()
The values() method returns a new iterator object that contains the values for each element in the Map object in insertion order.
Returns: Iterator the iterator that can be used in for of loops
Sample
Last updated