The syntax of Map.clear() method is:
void clear()
This clear() method of Map removes all entries from the map.
Map.clear() returns value of type void
.
In this example,
map
with initial key/value pairs.clear()
method to remove all entries from map
.map
after clearing it to standard output.void main() {
var map = {'a': 1, 'b': 2};
map.clear();
print(map);
}
{}
In this example,
map
with initial key/value pairs.clear()
method to remove all entries from map
.map
after clearing it to standard output.void main() {
var map = {'x': 'apple', 'y': 'banana'};
map.clear();
print(map);
}
{}
In this example,
map
with initial key/value pairs representing IDs and names.clear()
method to remove all entries from map
.map
after clearing it to standard output.void main() {
var map = {'id1': 'John', 'id2': 'Doe'};
map.clear();
print(map);
}
{}
In this Dart tutorial, we learned about clear() method of Map: the syntax and few working examples with output and detailed explanation for each example.