Opposite function of append

I was wondering if there is an opposite function to append.

According to the docs, append appends one or more values to a slice and returns the resulting slice.

Is there a function that removes/deletes one or more values to a slice and returns the resulting slice?

Example:

{{ $s := slice "a" "b" "c" }}
{{ $s = $s | delete "b"}}
{{/* $s now contains a []string with elements "a", "c" */}}

If there is no such function, what is the recommended approach to deleting a []string is in the example above?

1 Like

try with

or the complement function.

not checked by myself

1 Like

As @ju52 mentioned, use symdiff

{{ $s := slice "a" "b" "c" }}
{{ $s = $s | symdiff (slice "b") }}
2 Likes