Class Map

Map objects are collections of key/value pairs where both the keys and values may be arbitrary ECMAScript language values. A distinct key value may only occur in one key/value pair within the Map's collection. Key/value pairs are stored and iterated in insertion order.

API Version:

Available from version 21.2.

PropertyDescription
size: NumberNumber of key/value pairs stored in this map.
ConstructorDescription
Map()Creates an empty map.
Map(Iterable)If the passed value is null or undefined then an empty map is constructed.
MethodDescription
clear()Removes all key/value pairs from this map.
delete(Object)Removes the entry for the given key.
entries()Returns an iterator containing all key/value pairs of this map.
forEach(Function)Runs the provided callback function once for each key/value pair present in this map.
forEach(Function, Object)Runs the provided callback function once for each key/value pair present in this map.
get(Object)Returns the value associated with the given key.
has(Object)Returns if this map has value associated with the given key.
keys()Returns an iterator containing all keys of this map.
set(Object, Object)Adds or updates a key/value pair to the map.
values()Returns an iterator containing all values of this map.

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

size: Number

Number of key/value pairs stored in this map.


Map()

Creates an empty map.


Map(values: Iterable)

If the passed value is null or undefined then an empty map is constructed. Else an iterator object is expected that produces a two element array-like object whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.

Parameters:

  • values - The initial map values

clear(): void

Removes all key/value pairs from this map.


delete(key: Object): Boolean

Removes the entry for the given key.

Parameters:

  • key - The key of the key/value pair to be removed from the map.

Returns:

  • true if the map contained an entry for the passed key that was removed. Else false is returned.

entries(): ES6Iterator

Returns an iterator containing all key/value pairs of this map. The iterator produces a series of two-element arrays with the first element as the key and the second element as the value.


forEach(callback: Function): void

Runs the provided callback function once for each key/value pair present in this map.

Parameters:

  • callback - The function to call, which is invoked with three arguments: the value of the element, the key of the element, and the Map object being iterated.

forEach(callback: Function, thisObject: Object): void

Runs the provided callback function once for each key/value pair present in this map.

Parameters:

  • callback - The function to call, which is invoked with three arguments: the value of the element, the key of the element, and the Map object being iterated.
  • thisObject - The Object to use as 'this' when executing callback.

get(key: Object): Object

Returns the value associated with the given key.

Parameters:

  • key - The key to look for.

Returns:

  • The value associated with the given key if an entry with the key exists else undefined is returned.

has(key: Object): Boolean

Returns if this map has value associated with the given key.

Parameters:

  • key - The key to look for.

Returns:

  • true if an entry with the key exists else false is returned.

keys(): ES6Iterator

Returns an iterator containing all keys of this map.


set(key: Object, value: Object): Map

Adds or updates a key/value pair to the map.

You can't use JavaScript bracket notation to access map entries. JavaScript bracket notation accesses only properties for Map objects, not map entries.

Parameters:

  • key - The key object.
  • value - The value to be associated with the key.

Returns:

  • This map object.

values(): ES6Iterator

Returns an iterator containing all values of this map.