How to Iterate Over a Map in Go with range

Iterate over a Go map using the range keyword to access keys and values in a single loop.

Use the range keyword on a map to iterate over its key-value pairs, where the first variable holds the key and the second holds the value.

m := map[string]int{"a": 1, "b": 2}
for k, v := range m {
    fmt.Println(k, v)
}

If you only need the keys, use a blank identifier (_) for the value; if you only need the values, use it for the key.