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) S

Parameters & Attributes

NameTypeDescription
sSInput slice; may share its backing array.
iintIndex or start position.
jintSecond 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)}
Go Reference