In Go, an array is a numbered sequence of elements of a specific length. In typical Go code, slices are much more common; arrays are useful in some special scenarios. |
|
|
|
|
|
|
|
Here we create an array |
|
We can set a value at an index using the
|
|
The builtin |
|
Use this syntax to declare and initialize an array in one line. |
|
You can also have the compiler count the number of
elements for you with |
|
If you specify the index with |
|
Array types are one-dimensional, but you can compose types to build multi-dimensional data structures. |
|
You can create and initialize multi-dimensional arrays at once too. |
|
Note that arrays appear in the form |
|
Next example: Slices.