In Go language, we can add a key-value pair to a map using the following syntax:
main.go17 chars2 lines
Here, the map is the name of the map variable to which we want to add a key-value pair. key is the key that we want to add and value is the value associated with that key.
Let's see an example of how to add a key-value pair to a map in Go:
main.go321 chars19 linesIn the above code, we have declared and initialized a map studentAgeMap. Then we have added a new key-value pair to the map using the assignment operator =. Finally, we printed the complete map using the fmt.Println() function.
Output:
main.go37 chars2 lines
gistlibby LogSnag