Menu
Coddy logo textTech

Introduction to Arrays

Part of the Fundamentals section of Coddy's GO journey — lesson 67 of 109.

Arrays in Go store fixed-size collections of elements of the same type.

Declare an array of 5 integers:

var scores [5]int

Initialize an array with values:

var fruits = [3]string{"apple", "banana", "orange"}

Access array elements using index (starting from 0):

fmt.Println(fruits[1])

This displays:

banana

Modify an array element:

fruits[0] = "mango"
fmt.Println(fruits)

Result:

[mango banana orange]

Cheat sheet

Arrays in Go store fixed-size collections of elements of the same type.

Declare an array:

var scores [5]int

Initialize with values:

var fruits = [3]string{"apple", "banana", "orange"}

Access elements using index (starting from 0):

fmt.Println(fruits[1]) // banana

Modify elements:

fruits[0] = "mango"

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals