golang iterate over map code example
Example 1: go loop through map
for k, v := range m {
fmt.Printf("key[%s] value[%s]\n", k, v)
}
// or
for k := range m {
fmt.Printf("key[%s] value[%s]\n", k, m[k])
}
Example 2: golang iterate through map
var m = map[string]string{}
m["key"] = "value"
m["someOtherKey"] = "someOtherValue"
for key, value := range m {
fmt.Println(fmt.Sprintf("%s : %s", key, value))
}