To remove all the keys and values from a map in Go, we can loop over all the keys of the map using a for range loop and delete each key using the delete built-in function. Here's an example:
main.go211 chars15 lines
Alternatively, we can also create a new empty map using the make built-in function, which will overwrite the old map with the new empty map:
main.go184 chars13 lines
In both cases, we end up with an empty map with no keys or values.
gistlibby LogSnag