How to get length of a slices in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To get length of a slices, use len(slice) method it will count and return numbers of element of slices (array).

In golang the len() method used for counts element of slices.

Let’s start

package main
import "fmt"

func main() {
  slice := []int{1,2,3,4,5,6}
	fmt.Println("Length of slice", len(slice))
}

In the above program, we are accessing length of slice, let’s see the output.

Output:

Length of slice 6

Try it yourself

All the best 👍