I have a couple 2 dimensional slices in my Go program and I want to join them together.
However, append()
doesn't take this type.
cannot use myArray (type [][]string) as type []string in append
How do you append multi-dimensional slices using Go in an idiomatic way?
Use ...
to pass the second slice as variadic parameters to append. For example:
a := [][]string{{"a", "b"}, {"c", "d"}}
b := [][]string{{"1", "2"}, {"3", "4"}}
a = append(a, b...)
playground example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With