Start learning free

LESSON 104 OF 671 · ARRAYS I

Accessing slice elements in Go

Lesson

We can access the data inside a slice using indices and the bracket notation ([]), just like we do for static arrays.

Slices also use zero-based indexing, so the first element in a slice has an index of 0.

array := []int{50, 60, 70}

fmt.Println(array[0]) // Output: 50

data := array[1]
fmt.Println(data) // Output: 60

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 3
    Ctrl + Enter to check