To check if a key of type int exists in a map in go, you can use the _, ok := map[key]
syntax.
The following code snippet demonstrates how to check if a key of type int exists in a map in go:
main.go420 chars21 lines
In the code snippet above, we create a map myMap
with integer keys and string values. We add some key-value pairs to the map and then check if a few keys exist using the if _, ok := myMap[key]; ok
syntax. If the key exists in the map, the value of ok
will be true
, otherwise it will be false
.
gistlibby LogSnag