[Go] Concatenate two slices with append

Created on November 30, 2026

You can concatenate two slices of the same element type by appending the second slice to the first. Use ... after the second slice to pass its elements to append.

package main

import "fmt"

func main() {
    first := []string{"one", "two"}
    second := []string{"three", "four"}

    combined := append(first, second...)
    fmt.Println(combined)
}
[one two three four]

Use the slice returned by append. It can share the first slice's underlying array if that array has room for the added elements.

Go