Script: Class Top Level Map
Class Map
- Object
- 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.
If the passed value is null or undefined then an empty map is constructed.
Method Summary
clear() : void
Removes all key/value pairs from this map.
delete(key : Object) : boolean
Removes the entry for the given key.
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.
Returns the value associated with the given key.
Returns if this map has value associated with the given key.
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.
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
publicMap()
Creates an empty map.
Map
publicMap(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
clear
clear() : void
Removes all key/value pairs from this map.
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. Elsefalse
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
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
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 elsefalse
is returned.
keys
keys() : ES6Iterator
Returns an iterator containing all keys of this map.
set
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
values() : ES6Iterator
Returns an iterator containing all values of this map.