Syntax

Go Create a Map Syntax

In Go, create a map: creates key-value pairs — ages := map[string]int{"Ada": 36}

Quick Answer

Syntax
ages := map[string]int{"Ada": 36}
GoSyntax

Create a Map

Code example
ages := map[string]int{"Ada": 36}

Creates key-value pairs.

Learn More

How to create a map in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Create a Map Syntax

Use ages := map[string]int{"Ada": 36}.

Related Syntax References

Frequently asked questions

What is the Go syntax for create a map?

Use this pattern: ages := map[string]int{"Ada": 36}

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify