Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Created April 25, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arehmandev/b081d50bf7def5d8660aa706c3410110 to your computer and use it in GitHub Desktop.
Save arehmandev/b081d50bf7def5d8660aa706c3410110 to your computer and use it in GitHub Desktop.
Iteratively remove elements from slice
package main
import "fmt"
func main() {
slice := []string{"TEST1", "TEST2", "TEST3", "TEST4"}
fmt.Println("SLICE AT START", slice)
for i := len(slice) - 1; i >= 0; i-- {
fmt.Println("REMOVE FROM ARRAY:", slice[i])
slice = append(slice[:i], slice[i+1:]...)
fmt.Println("SLICE:", slice)
}
fmt.Println("SLICE AT END", slice)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment