In Go, you can find the number of key-value pairs in a map using the len()
function. Here's an example:
package main
import "fmt"
func main() {
// Create a map
m := map[string]int{
"apple": 5,
"banana": 3,
"orange": 7,
}
// Get the number of key-value pairs in the map
count := len(m)
fmt.Println("Number of key-value pairs:", count)
}
Output:
Number of key-value pairs: 3
In the above example, the len()
function is used to get the number of key-value pairs in the map m
. The result is then printed using fmt.Println()
.