← Go Programming learning path
Go Programming · Module 4 of 10

Arrays, slices and maps

Store collections with slices and maps.

📖 Key ideas

  1. Arrays have fixed size: [3]int.
  2. Slices are flexible views: []int{1, 2, 3}.
  3. append adds to a slice: s = append(s, 4).
  4. Maps: m := map[string]int{"a": 1}.
  5. 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