Get an array's length with len():
nums := [5]int{1, 2, 3, 4, 5}
fmt.Println(len(nums)) // 5
The length is always the declared size, even if you haven't set all values. len() works at compile time for arrays since the size is known.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Getting the size
Get an array's length with len():
nums := [5]int{1, 2, 3, 4, 5}
fmt.Println(len(nums)) // 5
The length is always the declared size, even if you haven't set all values. len() works at compile time for arrays since the size is known.