To remove a key and value from a map in Go, you can use the delete
function. The delete
function takes two arguments: the map to delete from, and the key to delete. Here's an example:
main.go153 chars7 lines
In this example, we first define a map with some key/value pairs. We then use delete
to remove the key/value with the key "b". Finally, we print out the map to verify that the "b" key/value has been removed.
Note that if you try to delete a key that doesn't exist in the map, there will be no error, and no action will be taken.
gistlibby LogSnag