← Go Programming learning pathGo Programming · Module 4 of 10
Arrays, slices and maps
Store collections with slices and maps.
📖 Key ideas
- Arrays have fixed size: [3]int.
- Slices are flexible views: []int{1, 2, 3}.
- append adds to a slice: s = append(s, 4).
- Maps: m := map[string]int{"a": 1}.
- Check map keys: v, ok := m["x"].
💡 Real-life example: An array is a fixed train with 3 coaches; a slice is a train you can attach more coaches to.
SliceDynamic view over an array
appendAdds elements to a slice
MapKey-value collection
lenReturns length