9951 explained code solutions for 126 technologies


golangHow to iterate over map


package main

func main() {
  mp := make(map[string]string)

  mp["name"] = "Joe"
  mp["position"] = "president"
  
  for k, v := range mp {
    print(k, ": ", v, "; ")
  }
}ctrl + c
package main

default package declaration

func main() {

declare main function that will be launched automatically

for k, v := range mp

iterate over mp map

print(k, ": ", v, "; ")

k will contain current key and v will contain current value