当前第2页 返回上一页
具体的代码实现如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
func SliceDelete() {
seq := []string{ "a" , "b" , "c" , "d" , "e" , "f" , "g" }
index := 3
fmt.Println(seq[:index], seq[index+1:])
seq = append(seq[:index], seq[index+1:]...)
fmt.Println(seq)
}
OutPut Result:
[a b c] [e f g]
[a b c e f g]
|
Slice删除元素的操作过程
1 2 3 4 5 6 7 8 9 10 11 12 | a b c d e f g
-------------------------------------
| |
↓ seq[:index] ↓ seq[index+1:]
a b c e f g
------------- -------------
| |
| |
↓ ↓
a b c e f g
----------------------------------
append(seq[:index], seq[index+1:]...)
|
更多golang知识请关注golang教程栏目。
以上就是golang如何删除数组中的元素的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
go语言标准库之strconv
总结 go 的数据类型
go语言反射的使用
最简单的go dockerfile编写姿势,没有之一!
golang四舍五入保留两位小数
golang学习笔记for循环语句
golang令牌桶实现 [go-rate] 速率限制器
生产环境遇到一个 go 问题,整组人都懵逼了...
关于golang gopath的新用法
关于golang中方法的receiver为指针和不为指针的区别
更多相关阅读请进入《golang》频道 >>
老貘
一个与时俱进的Go编程知识库。
转载请注明出处:木庄网络博客 » golang如何删除数组中的元素