Golang map type example

Hi 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.

map type, golang

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.

Stay tuned working on React Js Cheat Sheets Book

Related Posts