How to concatenate two slices in Golang?

To concatenate two slices in Golang, you can use the append() function. Here's an example:

package main import "fmt" func main() { // Creating two slices slice1 := []int{1, 2, 3} slice2 := []int{4, 5, 6} // Concatenating the slices using append() result := append(slice1, slice2...) // Printing the concatenated slice fmt.Println(result) }

In this example, we have two slices slice1 and slice2. We concatenate them using the append() function with the ... operator to unpack slice2 into individual elements. The result is stored in the result variable, which is then printed to the console.

Output:

[1 2 3 4 5 6]