Golang map type example
May 13, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, we are going to learn how to define map type in golang, here we will use static type to define the concept in golang.
As we know in the map we have defined keys and values to store data.
So first we have to define their key type and their value type.
let’s assume we want to use the key as a string and value as an int so we have to define it like below example.
package main
import "fmt"
func main() {
// here we are define map type
m := make(map[string]int)
m["k1"] = 7
m["k2"] = 13
fmt.Println("map:", m)
}
When you run it, you will get map key values in your golang console, let’s check the output.
All the best 👍