121 lines
2.3 KiB
Markdown
121 lines
2.3 KiB
Markdown
# Map
|
|
|
|
A Map object holds key-value pairs, where any value (both objects and primitive values) may be used as either a key or a value. Insertion order is remembered, which allows iteration in that order.
|
|
|
|
### set(key, value) <sub>function</sub>
|
|
|
|
Add or update an entry in the Map with the specified key and value.
|
|
|
|
|
|
|
|
**key**: The key of the element to add or update.
|
|
|
|
**value**: The value associated with the key.
|
|
|
|
|
|
**Returns**: The Map object (for chaining).
|
|
|
|
|
|
### get(key) <sub>function</sub>
|
|
|
|
Return the value associated with the specified key, or undefined if no
|
|
such key exists.
|
|
|
|
|
|
|
|
**key**: The key of the element to retrieve.
|
|
|
|
|
|
**Returns**: The value associated with the key, or undefined if not found.
|
|
|
|
|
|
### has(key) <sub>function</sub>
|
|
|
|
Return a boolean indicating whether the Map contains an element with the
|
|
specified key.
|
|
|
|
|
|
|
|
**key**: The key to test for presence in the Map.
|
|
|
|
|
|
**Returns**: True if the key is found, otherwise false.
|
|
|
|
|
|
### delete(key) <sub>function</sub>
|
|
|
|
Remove the specified key and its associated value from the Map, if it exists.
|
|
|
|
|
|
|
|
**key**: The key to remove.
|
|
|
|
|
|
**Returns**: True if an element was removed, otherwise false.
|
|
|
|
|
|
### clear() <sub>function</sub>
|
|
|
|
Remove all entries from the Map, leaving it empty.
|
|
|
|
|
|
|
|
**Returns**: None
|
|
|
|
|
|
### size <sub>accessor</sub>
|
|
|
|
(read only)
|
|
|
|
A read-only property returning the number of key-value pairs in the Map.
|
|
|
|
|
|
|
|
**Returns**: The number of entries in the Map.
|
|
|
|
|
|
### forEach(callbackFn, thisArg) <sub>function</sub>
|
|
|
|
Execute a provided callback function once per each key-value pair in the Map,
|
|
in insertion order.
|
|
|
|
|
|
|
|
**callbackFn**: A function(value, key, map) to execute on each entry.
|
|
|
|
**thisArg**: Optional. A value to use as 'this' when executing callbackFn.
|
|
|
|
|
|
**Returns**: None
|
|
|
|
|
|
### values() <sub>function</sub>
|
|
|
|
Return a new Iterator object that contains the values for each element
|
|
in the Map, in insertion order.
|
|
|
|
|
|
|
|
**Returns**: An iterator of the Map's values.
|
|
|
|
|
|
### keys() <sub>function</sub>
|
|
|
|
Return a new Iterator object that contains the keys for each element in
|
|
the Map, in insertion order.
|
|
|
|
|
|
|
|
**Returns**: An iterator of the Map's keys.
|
|
|
|
|
|
### entries() <sub>function</sub>
|
|
|
|
Return a new Iterator object that contains the [key, value] pairs for
|
|
each element in the Map, in insertion order.
|
|
|
|
|
|
|
|
**Returns**: An iterator of [key, value] pairs.
|
|
|