The (native) JavaScript Map object holds key-value pairs. Any value (both objects and primitive values) may be used as either a key or a value.

Documentation Map by Mozilla Contributors, licensed under CC-BY-SA 2.5.

Constructor

new(?iterable:Any)

An Array or other iterable object whose elements are key-value pairs (arrays with two elements, e.g. [[ 1, 'one' ],[ 2, 'two' ]]). Each key-value pair is added to the new js.Map; null values are treated as undefined.

Variables

read onlysize:Int

The number of key/value pairs in the js.Map object.

Methods

clear():Void

Removes all key/value pairs from the Map object.

delete(key:K):Bool

Returns true if an element in the js.Map object existed and has been removed, or false if the element does not exist. has(key) will return false afterwards.

entries():Iterator<KeyValue<K, V>>

Returns a new Iterator object that contains an array of KeyValue for each element in the js.Map object in insertion order.

forEach(callback:(value:V, key:K, map:Map<K, V>) ‑> Void, ?thisArg:Any):Void

Calls callback once for each key-value pair present in the js.Map object, in insertion order.

If a thisArg parameter is provided to forEach, it will be used as the this value for each callback.

get(key:K):Null<V>

The value associated to the key, or null if there is none.

has(key:K):Bool

A boolean asserting whether a value has been associated to the key in the js.Map object or not.

keys():Iterator<K>

Returns a new Iterator object that contains the keys for each element in the js.Map object in insertion order.

set(key:K, value:V):Map<K, V>

Sets the value for the key in the Map object. Returns the js.Map object.

values():Iterator<V>

Returns a new Iterator object that contains the values for each element in the js.Map object in insertion order.