There are 2 similar examples.
countryCapitalMap = make(map[string]string) countryCapitalMap["France"] = "Paris" countryCapitalMap["Italy"] = "Rome" countryCapitalMap["Japan"] = "Tokyo" countryCapitalMap["India"] = "New Delhi" for country := range countryCapitalMap { fmt.Println("Capital of",country,"is",countryCapitalMap[country]) } Result:
Capital of France is Paris
Capital of Italy is Rome
Capital of Japan is Tokyo
Capital of India is New Delhi
Those. I get both the key value and the value by key.
Option 2
x2 := make(map[int]string) x2[5] = "message" x2[1] = "Hello" for key := range x2 { fmt.Println("key[" + string(key) + "] is: " + x2[key]) if x2[key] == "message" { delete(x2, key) } } Result:
key [] is: message
key [] is: Hello
Why in this case I do not get the key value?