Run ❯
×
Change Orientation
Change Theme, Dark/Light
package main import ("fmt") func main() { a := map[string]int{"one": 1, "two": 2, "three": 3, "four": 4} var b []string // defining the order b = append(b, "one", "two", "three", "four") for k, v := range a { // loop with no order fmt.Printf("%v : %v, ", k, v) } fmt.Println() for _, element := range b { // loop with the defined order fmt.Printf("%v : %v, ", element, a[element]) } }
two : 2, three : 3, four : 4, one : 1,
one : 1, two : 2, three : 3, four : 4,