Go – Map Length

To get length of map in Go programming, call len() function and pass map as argument to it. The function returns an integer representing the number of key:value pairs in the map.

In this tutorial, we will learn how to use len() function to get the length of a given map.


The syntax to find the length of Map x is


Return Value

An integer.


In the following program, we take a map from string to string, and find its length.


package main

import "fmt"

func main() {
	map1 := map[string]string{
		"a": "apple",
		"b": "banana",

	var result int = len(map1)
	fmt.Print("Length of map : ", result)


Length of map : 2


In this Golang Tutorial, we learned how to find the length of a Map, with the help of example programs.