Go cheatsheet - Slice Utilities
Slice
Empty a slice
a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
a = a[:0]
// or
a = nil
Prepend
b := []int{2, 3, 4}
b = append([]int{1}, b...)
Remove
a = append(a[:i], a[i+1:]...)
Insert at index
s = append(s, 0)
copy(s[i+1:], s[i:])
s[i] = x
Index...
hn.0xbf.me2 min read