How to get array length in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we are going to learn how we can get array length in golang, here we will built in the method of go len() to get array length.

Well, First we will create an array of numbers and store it in a variable, after that we will use the len() method to get the length of the variable.

Let’s start the code…

package main
import "fmt"

func main() {
	a := []int{1, 2, 3, 4}

When we run the above program, we will get a 4, which means an array has 4 elements, and the length of the array is 4.

Let’s see actual output of the code.

get, array length, golang

Try it yourself

All the best 👍

Follow me on Twitter