Go slices

A slice is a dynamically sized view over an underlying array. Its length is the number of accessible elements, while its capacity describes how far it can grow before a new underlying array is needed.

Minimal example

go
func main() {
    values := []int{1, 2}
    values = append(values, 3)
    fmt.Println(len(values), cap(values))
}

Learn this concept

Lesson 1.5 · Structs, pointers, slices and maps

Used in exercises

Exercise 1.8 · Practice: write your first Go program Exercise 1.15 · Table-driven tests with a fake clock, plus one race test Exercise 1.26 · Optional: Sliding window log limiter Exercise 8.14 · Mermaid sequence linter Exercise 8.15 · Latency percentile package
Prerequisite conceptsGo functions