Contents
Roadmap info from roadmap website
Slices
Slices are similar to arrays but are more powerful and flexible. Like arrays, slices are also used to store multiple values of the same type in a single variable. However, unlike arrays, the length of a slice can grow and shrink as you see fit.
-
Slices hold references to an underlying array, and if you assign one slice to another, both refer to the same array.
-
@video@Learn Go Programming - Slices (by freeCodeCamp on YouTube)
Array vs Slice
Slices:
- Slices are similar to arrays, but are more powerful and flexible.
- Like arrays, slices are also used to store multiple values of the same type in a single variable.
- However, unlike arrays, the length of a slice can grow and shrink as you see fit.
Capacity vs length
- len() function - returns the length of the slice (the number of elements in the slice)
- cap() function - returns the capacity of the slice (the number of elements the slice can grow or shrink to)