Go — Arrays (basics)

--

In GO an array is a sequence of elements defined by a specific length. This is unlike other high-level programming languages like JavaScript, Python, and many more.

In GO arrays are always the same length, as they are defined. Here is an example of an initialization of an array of length 5 containing all zeroes, in GO:

We can then access or set new values for each of the “spots” in the array:

The previously mentioned length of an array can also be found by the function: “len”:

When initializing a new array, we can also put in the values we want on each place in the array, called initialization and declaration:

More often than not you will usually see “slices” in GO, than arrays.
For Slices see my next article, which will describe the differences between arrays and slices in GO.

--

--

Nikolaj Johannes Skole Jensen
Nikolaj Johannes Skole Jensen

Written by Nikolaj Johannes Skole Jensen

Fullstack developer living in Denmark. Experience with both Web- and App development.

No responses yet