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