Foundations Updated 2026-09 View as Markdown

Arrays

Arrays are essentially storage spaces that can be filled with as much data as one would like. Variables, unlike arrays, can only contain one piece of data.

Arrays#

Arrays are essentially storage spaces that can be filled with as much data as one would like. Variables, unlike arrays, can only contain one piece of data. Now there are some caveats. For instance, an array is syntactically created using one data type, just like variables. Yet, an array grants ease of access and far more capabilities when considering large/vast amounts of data compared to a variable(single storage space/value).

Examples#

go
// An array named favNums filled with 3 integers
var favNums[3] int

// Insert data into the array
// The first storage space will be assigned the value of 1.
favNums[0] = 1
// The second storage space will be assigned the value of 2.
favNums[1] = 2
// The third and final storage space will be assigned the value of 3.
favNums[2] = 3

An alternative syntax to the creation of arrays in golang is:

go
favNums := [4] int {50, 25, 30, 33}

In order to access members of an array, reference the storage space’s address or number you used to create it.

go
fmt.Println(favNums[0])

output:

go
50
Exercise

Try it

run this one locally

Expected output

hello world
3

Get the Go agent pack

A battle-tested AGENTS.md, the review checklist, and the failure-mode cheat sheet for Go. One email, then occasional updates when the tooling shifts. No course pitch.

Unsubscribe in one click. We never sell the list. Or just take the AGENTS.md now — no email needed.