Go: Concatenate slices
Use append
and add dots after the second slice:
a := []int{1, 2}
b := []int{11, 22}
a = append(a, b...) // a == [1 2 11 22]
The ...
unpacks b
. Without the dots, the code would attempt to append the slice as a whole, which is invalid since a
is not a slice of slices.
Comments
Be the first to comment!