Menu Close

Go – How to find length of map in go

In this tutorial, We are going to learn about How to find length of map in go. We can do it by using len() built-in function in go.

len() built-in function returns the length of map, slice, arrays and channel.

Function prototype:

func len(v Type) int

Return type:

len() built-in function returns 
the length of map, slice, arrays and channel.

Example with code:

package main

import (

  "fmt"

)

func main() {

  m := map[string]int {

    "Sunday": 0,

    "Mondaqy": 1,

    "Tuesday": 2,

  }

  fmt.Println("Size of map: ", len(m))
}

Output:

Size of map: 3

To learn more about golang, You can refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

 https://golang.org/doc/
https://golang.org/pkg/
https://golang.org/pkg/fmt/
https://golang.org/pkg/fmt/#Println
Posted in builtin, golang

Leave a Reply

Your email address will not be published.

Contact Us