JavaScripture
Contribute via GitHub Feedback

Map : Object

Maps allow associating keys and values similar to normal Objects except Maps allow any Object to be used as a key instead of just Strings and Symbols. Maps use get() and set() methods to access the values stored in the Map. A Map are often called a HashTable or a Dictionary in other languages.

Constructors

new Map() : Map

Creates an empty Map.

Example:

Run

Results:

 

new Map(iterable : Object) : Map

Creates a Map by iterating over iterable and using the first element of the iterator value as the key and second element as the value.

Example:

Run

Results:

 

Instance Properties

size : Number

The number of key/value pairs in this.

Example:

Run

Results:

 

Instance Methods

clear() : undefined

Clears the key/value pairs from this.

Example:

Run

Results:

 

delete(key : Object) : Boolean

Removes key and its corresponding value from this. Returns true if key was in this before deleting it.

Example:

Run

Results:

 

entries() : Iterator<Array>

Returns an iterator of the index and items in this where the valuess of the iterator are of the form [key : Object, value : Object]. The entries function is also returned for this[Symbol.iterator] so you can iterate over this directly to get the entries. See also keys() and values().

Example:

Run

Results:

 

forEach(callback : Function, [thisArg : Object]) : undefined
callback(value : Object, key : Object, map : Map) : undefined

Calls callback for each key/value pair in this. The Map passed to callback is the this of the call to forEach.

Example:

Run

Results:

 

get(key : Object) : Object

Returns the value stored for key. If no value is stored, returns undefined. See also has() and set().

Example:

Run

Results:

 

has(key : Object) : Boolean

Returns true if the map has a value stored for key.

Example:

Run

Results:

 

keys() : Iterator

Returns an iterator of the keys in this. See also entries() and values().

Example:

Run

Results:

 

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

Stores value in this at the specified key. If a value is already stored for that key, it is replaced with value. Returns this. See also get() and has().

Example:

Run

Results:

 

values() : Iterator

Returns an iterator of the values in this. See also entries() and keys().

Example:

Run

Results: