Maps in Go
October 19, 2022About 1 min
Maps in Go 관련
The Go Handbook – Learn Golang for Beginners
Golang is an awesome, simple, modern, and fast programming language. It’s compiled, open source, and strongly typed. Golang – also called Go – was created by Google engineers with these main goals: make their projects compile (and run) faster be sim...
The Go Handbook – Learn Golang for Beginners
Golang is an awesome, simple, modern, and fast programming language. It’s compiled, open source, and strongly typed. Golang – also called Go – was created by Google engineers with these main goals: make their projects compile (and run) faster be sim...
A map is a very useful data type in Go.
In other language it’s also called a dictionary or hash map or associative array.
Here’s how you create a map:
agesMap := make(map[string]int)
You don’t need to set how many items the map will hold.
You can add a new item to the map in this way:
agesMap["flavio"] = 39
You can also initialize the map with values directly using this syntax:
agesMap := map[string]int{"flavio": 39}
You can get the value associated with a key using:
age := agesMap["flavio"]
You can delete an item from the map using the delete()
function in this way:
delete(agesMap, "flavio")