find the first element in an array in go

In Go, you can access the first element of an array by using index 0. Here is an example:

main.go
package main

import "fmt"

func main() {
    arr := [3]int{1, 2, 3}

    first := arr[0]

    fmt.Println(first) // Output: 1
}
129 chars
12 lines

In the code above, the first element of the arr array is accessed using index 0 and assigned to the first variable. The value of first is then printed to the console using the fmt.Println() function.

Note that the same method can be used to access any element of an array by using its index.

gistlibby LogSnag