How to append a slice to another slice in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we will learn to append slice to a another slice in golang, here we will use append() golang build in method.

So we will create two slices like following example.

package main
import "fmt"

func main() {
  x, y := []int{1, 2}, []int{3, 4}
  z := append(x, y...)

Here, we have created two slice x and y, use append method to concate slice and, store in third variable z.

Now You see the output here showing z value is [1, 2, 3, 4].


Golang, append, slice, example

Try it yourself

All the best 👍

Follow me on Twitter