| 1 |
--- |
| 2 |
title: collections.Delimit |
| 3 |
description: Returns a string by joining the values of the given slice or map with a delimiter. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [delimit] |
| 9 |
returnType: string |
| 10 |
signatures: ['collections.Delimit SLICE|MAP DELIMITER [LAST]'] |
| 11 |
aliases: [/functions/delimit] |
| 12 |
--- |
| 13 |
|
| 14 |
Delimit a slice: |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ $s := slice "b" "a" "c" }} |
| 18 |
{{ delimit $s ", " }} → b, a, c |
| 19 |
{{ delimit $s ", " " and "}} → b, a and c |
| 20 |
``` |
| 21 |
|
| 22 |
Delimit a map: |
| 23 |
|
| 24 |
> [!NOTE] |
| 25 |
> The `delimit` function sorts maps by key, returning the values. |
| 26 |
|
| 27 |
```go-html-template |
| 28 |
{{ $m := dict "b" 2 "a" 1 "c" 3 }} |
| 29 |
{{ delimit $m ", " }} → 1, 2, 3 |
| 30 |
{{ delimit $m ", " " and "}} → 1, 2 and 3 |
| 31 |
``` |