Ad space (banner)
Lesson 10 / 20

Working with maps (Map)

This lesson covers the map, which manages data as key-value pairs.

Writing Map<keyType, valueType> creates a structure where you look up a value by its key. It corresponds to a dictionary or associative array in other languages.

The sample code builds a map of products and prices — Map<String, int> prices = {'apple': 100, 'orange': 80}; — and reads a value out with prices['apple'].

A common early stumble is that reaching for a key that does not exist returns null. When you read from a map, stay aware of whether the key is actually there.

In professional work, JSON received from an API is very often handled as a Map, which makes Dart's map operations an essential everyday skill.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)