Delete a Go slice element by swapping it with the last item and truncating the slice length.
You delete an element from a Go slice by replacing it with the last element and then truncating the slice length.
i := 2 // index to delete
mySlice[i] = mySlice[len(mySlice)-1]
mySlice = mySlice[:len(mySlice)-1]
This method preserves order only if you don't care about the original sequence, as it swaps the target with the final item.
Go slices are fixed-size arrays with a length pointer, so you cannot simply remove an item without shifting everything else. This trick works like swapping the person you want to remove from a line with the person at the very back, then cutting the line short. It is the fastest way to delete an item when the order of the remaining items doesn't matter.