- Why do we need slices if we have arrays?
- How to define an empty slice of strings called
someSlice
? - What the following lines does?
append(someSlice, 'abc')
- How to retrieve the first element of the slice
someSlice
?
- Slices, similarly to arrays, are also have size and are index based but as opposed to arrays their size can be resized when needed so it makes them a flexible option in case where you can't define what should be exactly the size of an array or when an array is expected to be added with items over time.
var someSlice = []string{}
- Adds the string 'abc' to the end of the slice
someSlice
- Similarly to how it's done with arrays:
someSlice[0]