Standard library / slices
slices.Delete()
Removes the half-open range [i:j], shifts remaining elements and clears the unused tail. Panics for invalid range; retain the result. Expected stdout: '[1 4] [1 4 0 0]\n'.
Formal Syntax & Structure
go syntaxgo
func Delete[S ~[]E, E any](s S, i, j int) SParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
| i | int | Index or start position. |
| j | int | Second index or exclusive end position. |
Return Value
S
Removes the half-open range [i:j], shifts remaining elements and clears the unused tail. Panics for invalid range; retain the result.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { a := []int{1, 2, 3, 4} fmt.Println(slices.Delete(a, 1, 3), a)}