To take out the first element of the slice:
numbers := [] int { 3 , 14 , 159 , 26 , 53 , 58 } numbers = numbers [ 1 :] // remove element 0
To take out the last element of the slice:
numbers := [] int { 3 , 14 , 159 , 26 , 53 , 58 } numbers = numbers [: len ( numbers ) - 1 ] // remove last element
Removing elements in between two adjacent elements within a slice is quite straightforward too. You simply append the head of the original slice with the tail of the original slice, removing whatever is in between. In this case, you want to remove the element at index 2, which is 159:
numbers := [] int { 3 , 14 , 159 , 26 , 53 , 58 } numbers = append ( numbers [: 2 ], numbers [ 3 :] ... )
标签:slice,159,53,element,int,values,numbers,Go From: https://www.cnblogs.com/zhangzhihui/p/17747706.html