Slices in Go

This section explains the concept of slices in Go and its details such as slicing, appending slices, nil slices and finding slice length

Slices

Slices wrap arrays to give a more general, powerful, and convenient interface to sequences of data. Except for items with an explicit dimension such as transformation matrices, most array programming in Go is done with slices rather than simple arrays.

Slices hold references to an underlying array, and if you assign one slice to another, both refer to the same array. If a function takes a slice argument, changes it makes to the elements of the slice will be visible to the caller, analogous to passing a pointer to the underlying array.

A slice points to an array of values and also includes a length. Slices can be resized since they are just a wrapper on top of another data structure.

[]T is a slice with elements of type T.

Get hands-on with 1400+ tech skills courses.