Skip to content

Archive

Slice

2 articles
Go Updated 02 Sep 2025 2 min read

Practical Ways to Combine Slices in Go

Combining slices is common when data comes from several sources or processing stages. In Go, the standard approach is append, optionally with preallocated capacity when the final size is known. 1. Combine Slices with append package main import "fmt" func main() { slice1 := []int{1, 2, 3} slice2 := []int{4, 5, 6} slice3 := []int{7, 8, 9} combined := append(slice1, slice2...) combined = append(combined, slice3...) fmt.Println(combined) } Output:

Go Updated 02 Sep 2025 3 min read

Arrays and Slices in Go: Add, Delete, Search, Update, Sort, and Filter

Go arrays and slices are straightforward once you understand their different roles. Arrays have a fixed length that is part of their type, while slices are flexible views over an underlying array and are the collection type used most often in application code. The following examples use a slice of structs: type Person struct { Name string Age int } people := []Person{ {Name: "Alice", Age: 30}, {Name: "Bob", Age: 25}, {Name: "John", Age: 20}, {Name: "Zara", Age: 35}, } 1. Add an Element Use append: