How could I iterate through the slice and pass somewhere the slice except the current element? Seems append() function modifies the underlying slice as we could see in documentation. But anyway I still don't know how to reach this.
func main() {
args := []string{ "2", "3", "8" }
for i, _ := range args {
fmt.Println(append(args[:i], args[i+1:]...)) // or pass to function
}
fmt.Println(args)
}
result:
[3 8]
[3 8]
[3 8]
[3 8 8] // it is args now
what I expect:
[3 8]
[2 8]
[2 3]
I already saw this Why does append() modify the provided slice? (See example)
but what is the Capacity of the slice is the secret for me, and I dont understand why did I exceed it.