How to check key exists in a map Golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To check key exists in a golang map, use if...else statement with map['key'] if it will return value it’s means key exists in a golang map.

Today, I’m going show you how do i check key exists in golang map.

Let’s start

Check key exists in golang map

Here, we will create s sample map with some data and try to check key contain in map

package main
import (
	"fmt"
)

func main() {
  mymap := make(map[string]string)
  mymap["first"] = "aguidehub"
  mymap["second"] = "infinitbility"
  mymap["third"] = "sortoutcode"
  
  _, isExist := mymap["third"]
  fmt.Println("is third exists", isExist)
  
}

In the above program, we are trying to check key in map, let’s see the output.

Output:

is third exists true

Try it yourself

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts