Sobes.tech
Junior — Senior

Order of traversing map elements in Go

livecode

Task condition

Given a map[string]int structure containing three key-value pairs. What order will be used when iterating over this map?

m := map[string]int{"a": 1, "b": 2, "c": 3}

for key, val := range m {
    fmt.Println(key, val)
}

Answer: The iteration order is not guaranteed and may vary with each program execution.