package main import ( "fmt" "encoding/json" ) func main() { fmt.Println("Hello, playground") tm := make(map[int]int) for i := 0 ; i < 10 ; i++ { tm[i] = i ; } a, _ := json.Marshal(tm) fmt.Println(string(a)) finalMap := []int{} v := 0 _ = v arr := []int{5, 6, 7, 8 , 9, 4, 32 , 2, 11} for _, arrVal := range arr{ if val, ok := tm[arrVal] ; ok { finalMap = append(finalMap, val) delete(tm, arrVal) } } b, _ := json.Marshal(tm) fmt.Println(string(b)) for _, key := range tm { finalMap = append(finalMap, tm[key]) delete(tm, key) } c, _ := json.Marshal(finalMap) fmt.Println(string(c)) }