Arrays:
An array is a fixed-size collection of elements of the same type. The size of the array is set when it is created and cannot be changed. Arrays can be accessed using their index, and they are 0-indexed, meaning that the first element is at index 0.
syntax
var arrayName = [length]type{value1, value2, value3, ...}
arrayName := [length]type{value1, value2, value3, ...}
var fruitArray = [3]string{"apple", "banana", "cherry"}
numbers := [5]int{1, 2, 3, 4, 5}
Operations:
- Accessing an element: arr[i]
- Setting the value of an element: arr[i] = value
- Iterating through the elements: for i, value := range arr
- Appending elements to the end of the array
- Inserting elements at a specific index
- Removing elements at a specific index
- Sorting the array