Trying to add a string to an initialised array of array of interfaces.
matrix := [][]interface{}{{"cat", "cat", "cat"}}
a := [][]interface{}{{"tiger"}}
matrix = append(matrix, a...)
Output:
[[cat cat cat] [tiger]]
But I wanted tiger in together with [[cat cat cat tiger]] like this.
You are adding an array of interface (
a...) tomatrixan 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
Output: