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))
}
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))
}
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)
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us