Attributes > Maps


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


Create

Create New Map

create new map

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

new Map<String, Dynamic>()

Copy of Map

copy of map

Returns a shallow copy of the map.

Utils.copyMap(map)

Modify

Set (Assign Key to Value)

set key text to value object for map

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

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

Remove Item (using Key)

remove key text from map

Removes the entry for the specified key from the map.

map.remove([TEXT]);

Remove All Items

remove all items from map

Removes all entries from the map.

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

Access

Get (Value for Key)

value of text for map

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

map.get([TEXT])

Map has Key?

map has key text

Returns true if an entry exists for the given key.

map.exists([TEXT])

Map has Value?

map has value object

Returns true if the value exists in the map.

Utils.mapContainsValue(map, [VALUE])

Number of Items in Map

number of items in map

Returns the number of entries in the map.

Utils.mapCount(map)

Map is Empty?

map is empty

Returns true if the map contains no entries.

Utils.mapCount(map) == 0

Keys / Values of Map (as list)

keys of map as list

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")

For Each Item in Map ...

for each key in map

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

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

//loop over values
for(item in map) {
  [ACTION]
}