How to initialize an empty map in Golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I’m going to show you how I do initialize an empty map in Golang, to create an empty map I follow a basic style just I will not put any data in it.

Let’s start today’s tutorial How to initialize an empty map in Golang?

Here I will create a sample variable and store an empty map, then I will use the print method to check if it’s empty or not.

Okey, let’s start the code.

package main
 
import "fmt"
 
func main() {
    x := map[string]string{}
    fmt.Println(x)
}

when you run above program it will print map[] like in golang console.

let’s check the output.

get, initialize an empty 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