Maps in Go

From the Go cheat sheet · Data Types & Structures · verified Jul 2026

Maps

Working with maps (hash tables)

go
// Create map
m := make(map[string]int)
m["key"] = 42

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

// Check if key exists
val, ok := ages["Alice"]
🗺️ Hash tables with O(1) average access
🔑 Any comparable type can be a key
❌ Use delete() to remove entries
⚠️ Maps are not thread-safe by default

More Go tasks

Back to the full Go cheat sheet