.keys

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Mar 12, 2024
Contribute to Docs

In Dart, the .keys property returns an iterable collection containing all the keys in a map.

Syntax

myMap.keys
  • myMap: The map name that needs to be searched.

Example

The following example displays the usage of the .keys property:

void main() {
Map<String, String> adventurers = {
'001': 'Alice the Archer',
'002': 'Bob the Barbarian',
'003': 'Charlie the Cleric'
};
for (var id in adventurers.keys) {
print(id);
}
}

The above example produces the following output:

001
002
003

All contributors

Looking to contribute?

Learn Dart on Codecademy