map Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/map/ Mon, 08 Jun 2020 18:30:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 map Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/map/ 32 32 159787465 Length of a map in Go (Golang) https://vikasboss.github.io/length-map-golang/ https://vikasboss.github.io/length-map-golang/#respond Mon, 08 Jun 2020 18:29:59 +0000 https://vikasboss.github.io/?p=2208 The golang builtin function len() can be used to get the length of the map which is number of key-value pairs present in the map. Below is the format for using this...

The post Length of a map in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
The golang builtin function len() can be used to get the length of the map which is number of key-value pairs present in the map. Below is the format for using this function on the map.

len(mapName)

Let’s see a program

package main

import "fmt"

func main() {
    //Declare
    employeeSalary := make(map[string]int)

    //Adding a key value
    employeeSalary["Tom"] = 2000
    employeeSalary["Sam"] = 1200

    lenOfMap := len(employeeSalary)
    fmt.Println(lenOfMap)
}

Output

2

The post Length of a map in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/length-map-golang/feed/ 0 2208