Efficient delete of a slice element

Lets define a simple slice

    slice := make([]string, 0, 5)
    slice = append(slice, "element0")
    slice = append(slice, "element1")
    slice = append(slice, "element2")
    slice = append(slice, "element3")
    slice = append(slice, "element4")

Print its content and length

    for idx := range slice {
        fmt.Println(idx, "\t", slice[idx])
    }
    fmt.Println("length: ", len(slice))

Delete element2

// delete element2
    delElement := "element2"
    fmt.Println("element to delete:", "\t", delElement)
    for idx := range slice {
        if slice[idx] == delElement {
            slice[idx] = slice[len(slice)-1]
            slice[len(slice)-1] = ""
            slice = slice[:len(slice)-1]
            break
        }
    }

Print it with the updated length

    for idx := range slice {
        fmt.Println(idx, "\t", slice[idx])
    }
    fmt.Println("length: ", len(slice))
0