[Go] Prepend elements to a slice

Created on November 28, 2026

You can prepend elements to a slice by using append and placing three dots after the slice. append is variadic from its second argument onward, so you can pass a slice using the syntax someSlice....

package main

import "fmt"

func main() {
    dummySlice := []string{"one", "two", "three"}
    newSlice := append([]string{"zero"}, dummySlice...)
    fmt.Println(newSlice)
}

The program produces the following output.

[zero one two three]
Go