How to print map in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we will create a map variable, add some values, and will try to print it in the console.

Here, we are going to use the fmt.Println() method to print map variable values.

To create a map type variable we write like m := make(map[string]int).

Let’s write code and check the golang console.

package main

import "fmt"

func main() {

    m := make(map[string]int)

    m["k1"] = 7
    m["k2"] = 13

    fmt.Println("map:", m)
}

In the above code, we have created a map variable and added some data. check the following image for output.

print, map, 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