Start learning free

LESSON 110 OF 671 · ARRAYS I

Appending Item to Slice in Go

Lesson

We can add elements to the end of a slice using the built-in append() function.

append() takes the slice and one or more new values, and returns a new slice with those values added to the end:

arr1 := []int{1, 2, 3}
arr1 = append(arr1, 4)

// arr1 is now {1, 2, 3, 4}

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 2
    Ctrl + Enter to check