My Go Tutorial


The slice type is an abstraction built on top of Go’s array type, and so to understand slices we must first understand arrays.

var mySlice = []int{1,2,3,4,5}

var subSlice = mySlice[2:4]

So, in other words, the length of subSlice is two because subSlice only cares about two elements. However, the capacity is three because there are three elements left in the original array, starting from index two, which is the index that the subSlice array pointer points to.