SoFunction
Updated on 2025-03-05

How to get array length in Go language

This article describes the method of obtaining the length of an array in Go language. Share it for your reference. The specific implementation method is as follows:

Copy the codeThe code is as follows:
// getting the length of an array is silly, because the length is part of the array's static type
myArray := [3]int{1, 2, 3}
(len(myArray)) // prints 3
// getting the length of a slice
mySlice := []int{1, 2, 3}
(len(mySlice)) // prints 3

I hope this article will be helpful to everyone's Go language programming.