Length of Slice

To get length of slice in Go programming, call len() function and pass the slice as argument to it. len() function returns an integer, the length of slice.

The syntax to get the length of slice x is


Return Value

The function returns an integer value, representing the length of given slice.


In the following program, we take a slice in x, and find its length using len() function.


package main

import (

func main() {
	var x = []int{5, 8, 14, 7, 3}
	var xLen = len(x)
	fmt.Print("Length of slice is : ", xLen)


Length of slice is : 5


In this Golang Tutorial, we learned how to get length of a slice in Go programming using len() function, with the help of example program.