This is a creation in Article, where the information may have evolved or changed.
make(map[string]int) // mapping from strings to ints
We can also create a map with the syntax of map literals, as well as specify some initial key/value:
map[string]int{ "alice": 31, "charlie": 34,}
This is equivalent to
make(map[string]int)ages["alice"] = 31ages["charlie"] = 34
Use the built-in delete function to delete an element:
delete(ages, "alice") // remove element ages["alice"]
The iteration order of the map is indeterminate, and different hash function implementations may result in a different traversal order. In practice, the order of traversal is random and the order of each traversal is not the same. This is intentional, and each time a random traversal order can be used to enforce that the program does not rely on a specific hash function implementation. If you want to traverse key/value pairs sequentially, we must sort the key explicitly, and you can sort the string slice using the strings function of the sort package.
To put it simply, go through the map, take out all the keys and store them in a slice of the same length as the map, then sort the slice, and then traverse the slice to take out the key in the map.
By using the key index to get value, a value of two is returned, where the second value is present and the first value is the 0 value corresponding to value when it does not exist.
The go language does not provide a set type, but because the map key cannot be duplicated, it can be replaced by a map.