updated: 11th of February 2021
published: 22nd of November 2019
Arrays are a collection of values of the same type.
// create an array that can hold 2 elements
var stuff [2]string
// assign values to the array
stuff[0] = "blah"
stuff[1] = "bleh"
// shortcut to create an array and assign values
stuff := [2]string{"blah", "bleh"}
// let the go compiler dynamically determine the length of the array
stuff := [...]string{"blah", "bleh"}
// iterating an array
for i := 0; i < len(stuff); i++ {
// do something with stuff[i]
}
// iterating an array with range
// the first position (i) is the iteration number
// the second position (v) is the value
for i, v := range stuff {
// do something with i and v
}
// if the iteration position is not required
// _ is a throw away variable that does not need to be used
for _, v := range stuff {
// do something with v
}
https://tour.golang.org/moretypes/6
https://appdividend.com/2019/05/11/go-arrays-tutorial-with-example-arrays-in-golang-explained/
https://www.golangprograms.com/go-language/arrays.html
https://learning.oreilly.com/library/view/learning-go/9781492077206/ch03.html