To split an array in Go, you can use the slicing technique.
In this example,
numbers
with integer elements.numbers
based on indices.package main
import (
"fmt"
)
func main() {
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
slice1 := numbers[0:3]
slice2 := numbers[3:6]
slice3 := numbers[6:9]
fmt.Println(slice1, slice2, slice3)
}
[1 2 3] [4 5 6] [7 8 9]
In this tutorial, we learned How to Split an Array in Go language with well detailed examples.