A Simple GoLang Function to Merge n Number of Slices | Joining multiple slices Example
This is kinda a beginner question that how we can join multiple arrays or slices in any programming language. In golang slices are more popular options when it comes to merge them due to it's dynamic nature. In this post, I would like to share a very basic method to merge any number of slices with the help of golang Variadic function.
Merge Two Slices
Golang has built in append() to merge two slices.
s := append(sliceOne, sliceTwo...)
In our example we just leveraged using varags in a function to receive as many as slices we need then iterating over the arguments and apply the append method to join
Output of our mergeSlices function
[11 12 13 21 22 23 31 32 33]