collections.Slice
Returns a slice created from the given values.
- Syntax
- collections.Slice [VALUE...]
- Returns
- []any
- Alias
- slice
Usage
The collections.Slice function returns a slice created from the given values. The values may be of any data type, and you can mix data types within the same slice. Call the function without arguments to create an empty slice.
Examples
{{ $s := collections.Slice "a" "b" "c" }}
{{ $s }} → [a b c]Mixing data types:
{{ $s := collections.Slice "a" 1 true (collections.Slice 2 3) }}
{{ $s }} → [a 1 true [2 3]]Creating an empty slice:
{{ $s := collections.Slice }}
{{ $s }} → []Last updated:
November 24, 2026
:
content: Apply style guide to collections functions (04f2e2939)
Improve this page