create a map with a value of type array in go

To create a map with a value of type array in Go, you can use the following code:

main.go
// Initializing a map with a value of type array
myMap := make(map[string][3]int)

// Adding values to the map
myMap["myKey"] = [3]int{1, 2, 3}

// Accessing values in the map
myValue := myMap["myKey"]

// Outputting the value
fmt.Println(myValue)
248 chars
12 lines

In this example, we have initialized a map myMap which has string keys and array values of size 3. We have added a value to the map with key "myKey", and assigned an array {1, 2, 3} as the value.

To access values in the map, you can use the key to retrieve the corresponding value, as shown in the example. Finally, we output the value of the key "myKey" to the console, which will be the array {1, 2, 3}.

related categories

gistlibby LogSnag