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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nikolaj Johannes Skole Jensen

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