The syntax of Map.updateAll() method is:
void updateAll(V update(K key, V value))
This updateAll() method of Map updates all values.
Parameter | Optional/Required | Description |
---|---|---|
update | required | A function that updates each key-value pair. The function receives a key and its corresponding value as arguments. |
Map.updateAll() returns value of type void
.
In this example,
map
with initial key-value pairs.updateAll()
method on map
, passing a function that doubles each value.map
are doubled.void main() {
var map = {'a': 1, 'b': 2, 'c': 3};
map.updateAll((key, value) => value * 2);
print(map);
}
{a: 2, b: 4, c: 6}
In this example,
map
with initial key-value pairs.updateAll()
method on map
, passing a function that converts each value to uppercase.map
are in uppercase.void main() {
var map = {'x': 'A', 'y': 'B', 'z': 'C'};
map.updateAll((key, value) => value.toUpperCase());
print(map);
}
{x: A, y: B, z: C}
In this example,
map
with initial key-value pairs.updateAll()
method on map
, passing a function that adds a prefix 'delicious' to each value.map
.void main() {
var map = {'fruit': 'apple', 'vegetable': 'carrot', 'grain': 'rice'};
map.updateAll((key, value) => 'delicious ' + value);
print(map);
}
{fruit: delicious apple, vegetable: delicious carrot, grain: delicious rice}
In this Dart tutorial, we learned about updateAll() method of Map: the syntax and few working examples with output and detailed explanation for each example.