go array note
In Go, an array is a numbered sequence of elements of a specific length.
var a [5]int // create an array a that will hold exactly 5 ints.
fmt.Println("len:", len(a)) //Use builtin len returns the length of an array.
b := [5]int{1, 2, 3, 4, 5} //Use this syntax to declare and initialize an array in one line.
Array types are one-dimensional, but you can compose types to build multi-dimensional data structures.
var twoD [2][3]int
for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ {
twoD[i][j] = i + j
}
}
fmt.Println("2d: ", twoD)
}
You’ll see slices much more often than arrays in typical Go. We’ll look at slices next.