August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, I am going to present you with a way to find the dimensions of an array using the Go code found in dimensions.go. The same technique can be used for finding out the dimensions of a slice.
The Go code of dimensions.go is as follows:
package main
import (
"fmt"
)
func main() {
array := [12][4][7][10]float64{}
x := len(array)
y := len(array[0])
z := len(array[0][0])
w := len(array[0][0][0])
fmt.Println("x:", x, "y:", y, "z:", z, "w:", w)
}
There is an array called array with four dimensions. The len() function allows you to find its dimensions when provided with the right arguments. Finding the first dimension requires a call to len(array), whereas finding the second dimension ...
Read now
Unlock full access