Answers for "golang itterate map"

Go
0

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))
}
Posted by: Guest on June-12-2020
0

Go Looping through the map in Golang

package main
import ("fmt")

func main() {

  // create a map
  squaredNumber := map[int]int{2: 4, 3: 9, 4: 16, 5: 25}

  // for-range loop to iterate through each key-value of map
    for number, squared := range squaredNumber {
    fmt.Printf("Square of %d is %d\n", number, squared)
  }

}
Posted by: Guest on June-16-2022

Browse Popular Code Answers by Language