TopLevel
Class Map
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 Versioned:
From version 21.2.
Properties
size
:
Number
Number of key/value pairs stored in this map.
Constructor Summary
Map()
Creates an empty map.
Method Summary
clear()
:
void
Removes all key/value pairs from this map.
entries()
:
ES6Iterator
Returns an iterator containing all key/value pairs of this map.
forEach(callback
:
Function)
:
void
Runs the provided callback function once for each key/value pair present in this map.
forEach(callback
:
Function, thisObject
:
Object)
:
void
Runs the provided callback function once for each key/value pair present in this map.
keys()
:
ES6Iterator
Returns an iterator containing all keys of this map.
values()
:
ES6Iterator
Returns an iterator containing all values of this map.
Methods inherited from class
Object
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
Constructor Detail
Map
public 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
Method Detail
delete
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
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
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
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
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
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.
set
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.
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.