How to add key-value pairs to an existing map in Go?

To add key-value pairs to an existing map in Go, you can use the following syntax:

// Create an empty map m := make(map[string]int) // Add key-value pairs to the map m["key1"] = 1 m["key2"] = 2

Alternatively, you can also add key-value pairs during map initialization:

// Initialize a map with key-value pairs m := map[string]int{ "key1": 1, "key2": 2, }

If the key already exists in the map, assigning a new value to the existing key will update its value:

m["key1"] = 3 // Update the value of existing key "key1"

Remember, maps in Go are reference types, so you can pass them by reference to functions and modify them directly.