Sobes.tech
Junior — Middle

How can you determine the number of elements in a slice?

sobes.tech AI

Answer from AI

In Go, the len() function is used to determine the number of elements in a slice. It returns the count of elements contained in the slice.

Example:

slice := []int{1, 2, 3, 4, 5}
count := len(slice) // count will be 5
fmt.Println(count)