Essential Go Slices  Suggest an edit

Append to slice

Ways to append values to a slice.

Append a single value

a = append(a, hello)

Append multiple values

a = append(a, hello, world)

Append a slice to a slice

a := []string{"!"}
a2 := []string{"Hello", "world"}
a = append(a, a2...)
fmt.Printf("a: %#v\n", a)
a: []string{"!", "Hello", "world"}

  ↑ ↓ to navigate     ↵ to select     Esc to close