How to get length of a map in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To get length of a map, use len(myMap) method it will count and return numbers of element of map.

In golang the len() method used for counts element of map.

Let’s start

package main
import "fmt"

func main() {
  mymap := make(map[string]string)
  mymap["first"] = "aguidehub"
  mymap["second"] = "infinitbility"
  mymap["third"] = "sortoutcode"
	fmt.Println("Length of map", len(mymap))
}

In the above program, we are accessing length of map, let’s see the output.

Output:

Length of map 3

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

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.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts