golang check if key is in map
package main
import "fmt"
func main() {
// Create a map
myMap := map[string]int{
"one": 1,
"two": 2,
"three": 3,
}
// Check if key "two" exists in the map
keyToCheck := "two"
if value, exists := myMap[keyToCheck]; exists {
fmt.Printf("Key %s exists in the map with value %d\n", keyToCheck, value)
} else {
fmt.Printf("Key %s does not exist in the map\n", keyToCheck)
}
}