Go Maps Iterating the elements of a map

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


import fmt

people := map[string]int{
  "john": 30,
  "jane": 29,
  "mark": 11,

for key, value := range people {
  fmt.Println("Name:", key, "Age:", value)

Note that when iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next.

You can also discard either the keys or the values of the map, if you are looking to just grab keys or just grab values.

Got any Go Question?