Attributes > Maps


Read our article on Maps for an explanation of these blocks.


Modify

Set (Assign Key to Value)

set-map-block

Assigns the specified key to the given value for this map.

map.set([TEXT], [VALUE]);

Remove Item (using Key)

remove-map-block

Removes the entry for the specified key from the map.

map.remove([TEXT]);

Remove All Items

empty-map-block

Removes all entries from the map.

for(key in map.keys()) {
    map.remove(key);
}

Getters

Get (Value for Key)

get-map-block

Returns the entry for the given key, or null if it doesn't exist.

map.get("text")

Map has Key?

key-exists-map-block

Returns true if an entry exists for the given key.

map.exists([TEXT])

Map has Value?

value-exists-map-block

Returns true if the value exists in the map.

Utils.mapContainsValue(map, [VALUE])

Number of Items in Map

size-map-block

Returns the number of entries in the map.

Utils.mapCount(map)

Map is Empty?

is-empty-map-block

Returns true if the map contains no entries.

Utils.mapCount(map) == 0

Keys / Values of Map (as list)

list-keys-map-block

Returns the list of [keys or values] for this map. No specific order is guaranteed. (In other words, do not count on it being the same order in which you added the entries.)

Utils.mapToList(map, "keys")
Utils.mapToList(map, "values")

Create / Copy

Create New Map

create-map-block

Creates a new, empty map. Usually, you'll assign it to a map attribute right away.

new Map<String, Dynamic>()

Copy of Map

copy-map-block

Returns a shallow copy of the map.

Utils.copyMap(map)

Looping

For Each Item in Map ...

for-each-map-block

Lets you perform logic on each item in the map. Use the embedded item block to retrieve the current item being examined.

for(item in map.keys()) {
  [ACTION]
}