Menu
Coddy logo textTech

Introduction to Maps

Part of the Fundamentals section of Coddy's GO journey — lesson 84 of 109.

Maps in Go are key-value pairs, similar to dictionaries in other languages. They let you store and retrieve values using unique keys.

Create a map that associates string names with integer ages:

ages := map[string]int{
    "Alice": 25,
    "Bob": 30,
}

Access a value using its key:

aliceAge := ages["Alice"]
fmt.Println(aliceAge)

The output will be:

25

Add a new key-value pair:

ages["Charlie"] = 22

Cheat sheet

Maps in Go are key-value pairs that store and retrieve values using unique keys.

Create a map:

ages := map[string]int{
    "Alice": 25,
    "Bob": 30,
}

Access a value using its key:

aliceAge := ages["Alice"]

Add a new key-value pair:

ages["Charlie"] = 22

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals