[Golang] Initialize Two Dimensional Array/Slice


Initialization of 2-dimensional array/slice in Golang. [1]

The following is an example for 2-dimensional slice:

var letters = [][]string{
      []string{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"},
      []string{"a", "s", "d", "f", "g", "h", "j", "k", "l"},
      []string{"z", "x", "c", "v", "b", "n", "m"},
      []string{"ā", "ḍ", "ī", "ḷ", "ṁ", "ṃ", "ñ", "ṇ", "ṭ", "ū", "ŋ", "ṅ"},
}

If you need 2-dimensional array, just count and put the number in the brackets.


Tested on:

  • Ubuntu Linux 16.10
  • Go 1.7.5

References:

[1]
[2]GitHub - siongui/gopherjs-pali-virtual-keypad: Virtual Keyboard for Pāli input. Written in Go.
[3]golang can read slice value after variable redefined? : golang