append

The built-in Go function that adds values to the end of a slice and returns the updated slice.

In more detail

Always assign the result back, as in items = append(items, "scheduler"), because append may move the data to new, larger storage. Appending to a nil slice works, so there is no need to create an empty one first.

Example

names = append(names, "api", "worker")

Related terms

Taught in

References