In Golang, you can find the length of a slice using the built-in len()
function. Here's an example:
package main
import "fmt"
func main() {
// creating a slice
numbers := []int{1, 2, 3, 4, 5}
// finding the length of the slice
length := len(numbers)
fmt.Println("Length of the slice:", length)
}
Output:
Length of the slice: 5
In the above example, the len()
function is used to determine the length of the numbers
slice. The result is stored in the length
variable and then printed to the console.