[Solved] How to remove multiple items from map [closed]


The only other way to remove multiple items is by iterating through the map. This would remove all items, but you can wrap delete in some if to match your pattern:

package main

import "fmt"

func main() {
    var key string
    var m = make(map[string]int)
    m["x-edge-location"] = 10
    m["x-edge-request-id"] = 20
    m["x-edge-response-result-type"] = 30
    m["x-edge-result-type"] = 40

    fmt.Println(m)

    for key = range m {
        delete(m, key)
    }

    fmt.Println(m)
}

9

solved How to remove multiple items from map [closed]