切片如何删除指定元素?
```go
package main
import "fmt"
func main() {
a := []int{1, 2, 3, 4, 5}
index := getItemIndex(a, 3)
a1 := append(a[:index], a[index+1:]...)
fmt.Println(a1)
}
func getItemIndex(s []int, item int) (index int) {
for key, value := range s {
if value == item {
index = key
}
}
return
}
```
#4
更多评论
```go
a = append(a[:i], a[i+1:]...)
// or
a = a[:i+copy(a[i:], a[i+1:])]
```
https://github.com/golang/go/wiki/SliceTricks
#1