You are adding an array of interface (a...
) to matrix
an array of array of interface:
your array of array (matrix
) has now two arrays.
You would need to add to the first element of that array (matrix[0]
), in order to keep one array inside your array of array.
Example: https://goplay.tools/snippet/QcPTYIh1wJR
package main
import (
"fmt"
)
func main() {
matrix := [][]interface{}{{"cat", "cat", "cat"}}
a := [][]interface{}{{"tiger"}}
matrix = append(matrix, a...)
fmt.Println("matrix :", matrix)
matrix2 := [][]interface{}{{"cat", "cat", "cat"}}
b := append(matrix2[0], a[0]...)
matrix2[0] = b
fmt.Println("matrix2: ", matrix2)
}
Output:
matrix : [[cat cat cat] [tiger]]
matrix2: [[cat cat cat tiger]]