在Go中附加二维切片

sty*_*972 2 arrays go multidimensional-array

我的Go程序中有几个二维切片,我想将它们连接在一起。

但是,append()不要采用这种类型。

cannot use myArray (type [][]string) as type []string in append

如何以惯用方式使用Go附加多维切片?

Cer*_*món 8

使用...通过第二层为可变参数的参数追加。例如:

a := [][]string{{"a", "b"}, {"c", "d"}}
b := [][]string{{"1", "2"}, {"3", "4"}}
a = append(a, b...)
Run Code Online (Sandbox Code Playgroud)

操场的例子