Map Keys
Map keys
property returns an iterator to the keys in this Map. The type of elements in the returned iterator is as that of the keys in Map.
Syntax
The syntax to get an iterator for the keys of a Map myMap
is
myMap.keys
Examples
Get iterator to keys of a Map
In the following Dart Program, we take a Map myMap
with three key-value pairs, and get an iterator for the keys using Map.keys
property.
main.dart
</>
Copy
void main() {
var myMap = {'apple': 25, 'banana': 10, 'cherry': 6};
var keysIterator = myMap.keys;
print(keysIterator.elementAt(0));
print(keysIterator.elementAt(1));
print(keysIterator.elementAt(2));
}
Output
apple
banana
cherry
Conclusion
In this Dart Tutorial, we learned how to get an iterator for the keys of a Map, using Map.keys
property.