Just a few weeks until the 2021 JavaScript Full-Stack Bootcamp opens.
Signup to the waiting list!
- Create map
- Add item to map
- Lookup item from map
- Delete item from map
- Delete all content from a map
- Count the items in a map
- Put the keys of a map into a slice
Create map
// define map
var m1 map[int]string
// instantiate map
m1 = make(map[int]string)
// implict map instantiation
m2 := make(map[int]string)
// map literal
m3 := map[int]string{
1: "One",
9: "Nine"
}
Add item to map
m := map[int]string{
1: "One",
9: "Nine"
}
m[10] = "Ten"
// m contains 1, 9, 10
Lookup item from map
m := map[int]string{
1: "One",
9: "Nine"
}
item, ok := m[9] //item is "Nine; ok is true if the
//key was found, false otherwise
Delete item from map
m := map[int]string{
1: "One",
9: "Nine"
}
delete(m, 9)
//m contains only the `1` item
Delete all content from a map
Assign to the variable pointing to the map a new map:
m := map[int]string{
1: "One",
9: "Nine"
}
m = make(map[int]string) // m is an initialized, empty map
Count the items in a map
m := map[int]string{
1: "One",
9: "Nine"
}
l := len(m) // l == 2
Put the keys of a map into a slice
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
The 2021 JavaScript Full-Stack Bootcamp will start at the end of March 2021. Don't miss this opportunity, signup to the waiting list!
More go tutorials:
- Using NGINX Reverse Proxy to serve Go services
- Making a copy of a struct in Go
- The basics of a Go Web Server
- Sorting a map type in Go
- Go pointers in a nutshell
- Go Tags explained
- Go Date and Time Formatting
- JSON processing with Go
- Go Variadic Functions
- Go Strings Cheat Sheet
- The Go Empty Interface Explained
- Debugging Go with VS Code and Delve
- Named Go returns parameters
- Generating random numbers and strings in Go
- Filesystem Structure of a Go project
- Binary Search Algorithm Implemented in Go
- Using Command Line Flags in Go
- GOPATH Explained
- Build a Command Line app with Go: lolcat
- Building a CLI command with Go: cowsay
- Using Shell Pipes with Go
- Go CLI tutorial: fortune clone
- List the files in a folder with Go
- Use Go to get a list of repositories from GitHub
- Go, append a slice of strings to a file
- Go, convert a string to a bytes slice
- Visualize your local Git contributions with Go
- Getting started with Go CPU and memory profiling
- Solving the "does not support indexing" error in a Go program
- Measuring execution time in a Go program
- Building a Web Crawler with Go to detect duplicate titles
- Go Best Practices: Pointer or value receivers?
- Go Best Practices: Should you use a method or a function?
- Go Data Structures: Set
- Go Maps Cheat Sheet
- Generate implementations for generic types in Go
- Go Data Structures: Dictionary
- Go Data Structures: Hash Table
- Implement Events Listeners in Go through Channels
- Go Data Structures: Stack
- Go Data Structures: Queue
- Go Data Structures: Binary Search Tree
- Go Data Structures: Graph
- Go Data Structures: Linked List
- The complete guide to Go Data Structures
- Comparing Go Values
- Is Go object oriented?
- Working with a SQL Database in Go
- Using environment variables in Go
- Go tutorial: REST API backed by PostgreSQL
- Enabling CORS on a Go Web Server
- Deploying a Go Application in a Docker Container
- Why Go is a powerful language to learn as a PHP developer
- Go, remove the io.Reader.ReadString newline char
- Go, how to watch changes and rebuild your program
- Go, count the months since a date
- Accessing HTTP POST parameters in Go