An array is a collection of similar types of data. For example,
Suppose we need to record the age of 5 students. Instead of creating 5 separate variables, we can simply create an array.

Here is a syntax to declare an array in Golang.
Here, the size represents the length of an array. The list of elements of the array goes inside {}.
For example,
Output
In the above example, we have created an array named arrayOfInteger. The int specifies that the array arrayOfIntegers can only store integers.
An array can also be declared without specifying its size. The syntax to declare an array of undefined size is:
For example,
Output
In the above example, we have created an array named arrayOfString with an undefined size [...].
Here, if [] is left empty, it becomes a slice. So [...]is a must if we want an undefined size array.
Arrays can also be created using the shorthand notation :=. For example,
Output
In the above program, we have replaced the traditional syntax of creating an array with a shorthand notation (:=).
In Go, each element in an array is associated with a number. The number is known as an array index.
We can access elements of an array using the index number (0, 1, 2 …). For example,
In the above example, we have created an array named languages.

Here, we can see each array element is associated with the index number. And, we have used the index number to access the elements.
The array index always starts with 0. Hence, the first element of an array is present at index 0, not 1.
We can also use index numbers to initialize an array. For example,
Output
Here, we have initialized an array arrayOfIntegers using the index number. The arrayOfIntegers[0] = 5 represents that index 0 of arrayOfIntegers holds the value 5, index 1 holds value 10 and so on.
In Golang, we can also initialize the specific element of the array during the declaration. For example,
Output
Here, we have initialized the element at index 0 and 3 with values 7 and 9 respectively.
In this case, all other indexes are automatically initialized with value 0 (default value of integer).
To change an array element, we can simply reassign a new value to the specific index. For example,
Output
Here, we have reassigned a new value to index 2 to change the array element from "Cloudy" to "Stromy".
In Golang, we can use the len() function to find the number of elements present inside the array. For example,
Output
Here, we have used len() to find the length of an array arrayOfIntegers.
In Go, we can also loop through each element of the array. For example,
Output
Here, len() function returns the size of an array. The size of an array age is 3 here, so the for loop iterates 3 times; until all 3 elements are printed.
Arrays we have mentioned till now are called one-dimensional arrays. However, we can declare multidimensional arrays in Golang.
A multidimensional array is an array of arrays. That is, each element of a multidimensional array is an array itself. For example,
Output
Here, we have created a multidimensional array arrayInteger with 2 rows and 2 columns.
A multidimensional array can be treated like a matrix like this
