2015-01-25 19:08:13 +00:00
|
|
|
^title Map Class
|
|
|
|
|
|
2019-04-09 15:44:15 +00:00
|
|
|
An associative collection that maps keys to values. More details [here](../../maps.html).
|
2015-01-25 19:08:13 +00:00
|
|
|
|
2015-03-27 14:43:36 +00:00
|
|
|
## Methods
|
|
|
|
|
|
2015-02-27 07:08:36 +00:00
|
|
|
### **clear**()
|
2015-01-25 19:08:13 +00:00
|
|
|
|
2015-01-25 20:39:19 +00:00
|
|
|
Removes all entries from the map.
|
|
|
|
|
|
|
|
|
|
### **containsKey**(key)
|
|
|
|
|
|
|
|
|
|
Returns `true` if the map contains `key` or `false` otherwise.
|
2015-01-25 19:08:13 +00:00
|
|
|
|
|
|
|
|
### **count**
|
|
|
|
|
|
|
|
|
|
The number of entries in the map.
|
|
|
|
|
|
|
|
|
|
### **keys**
|
|
|
|
|
|
|
|
|
|
A [Sequence](sequence.html) that can be used to iterate over the keys in the
|
|
|
|
|
map. Note that iteration order is undefined. All keys will be iterated over,
|
|
|
|
|
but may be in any order, and may even change between invocations of Wren.
|
|
|
|
|
|
2015-01-26 01:42:36 +00:00
|
|
|
### **remove**(key)
|
|
|
|
|
|
2016-02-22 15:48:53 +00:00
|
|
|
Removes `key` and the value associated with it from the map. Returns the value.
|
2015-01-26 01:42:36 +00:00
|
|
|
|
|
|
|
|
If the key was not present, returns `null`.
|
2015-01-25 19:08:13 +00:00
|
|
|
|
|
|
|
|
### **values**
|
|
|
|
|
|
|
|
|
|
A [Sequence](sequence.html) that can be used to iterate over the values in the
|
|
|
|
|
map. Note that iteration order is undefined. All values will be iterated over,
|
|
|
|
|
but may be in any order, and may even change between invocations of Wren.
|
|
|
|
|
|
|
|
|
|
If multiple keys are associated with the same value, the value will appear
|
|
|
|
|
multiple times in the sequence.
|
|
|
|
|
|
|
|
|
|
### **[**key**]** operator
|
|
|
|
|
|
|
|
|
|
Gets the value associated with `key` in the map. If `key` is not present in the
|
|
|
|
|
map, returns `null`.
|
|
|
|
|
|
2015-09-22 14:59:54 +00:00
|
|
|
:::wren
|
2015-01-25 19:08:13 +00:00
|
|
|
var map = {"george": "harrison", "ringo": "starr"}
|
2015-10-18 22:56:52 +00:00
|
|
|
System.print(map["ringo"]) //> starr
|
|
|
|
|
System.print(map["pete"]) //> null
|
2015-01-25 19:08:13 +00:00
|
|
|
|
|
|
|
|
### **[**key**]=**(value) operator
|
|
|
|
|
|
|
|
|
|
Associates `value` with `key` in the map. If `key` was already in the map, this
|
|
|
|
|
replaces the previous association.
|
|
|
|
|
|
|
|
|
|
It is a runtime error if the key is not a [Bool](bool.html),
|
|
|
|
|
[Class](class.html), [Null](null.html), [Num](num.html), [Range](range.html),
|
|
|
|
|
or [String](string.html).
|