[Go] Append an element to the end of a slice

Created on November 30, 2026

Use append to add an element to the end of a slice. Assign its return value back to the slice variable to use the increased length.

var arr = []string{"one", "two"}
arr = append(arr, "three")

fmt.Printf("%#v", arr) // []string{"one", "two", "three"}

The example prints []string{"one", "two", "three"}.

Go