📙 Map

Use the dictionary-like Dart Map to manage key-value pairs

Basic Maps

file_type_dartlang maps.dart
  Map<String, dynamic> book = {
    'title': 'Moby Dick',
    'author': 'Herman Melville',
    'pages': 752,
  };

  book['title'];
  book['published'] = 1851;

Loop over a Map

file_type_dartlang maps.dart
  book.keys;
  book.values;
  book.values.toList();

  for (MapEntry b in book.entries) {
    print('Key ${b.key}, Value ${b.value}');
  }

  book.forEach((k, v) => print("Key : $k, Value : $v"));

Questions? Let's chat

Open Discord