| 1 |
--- |
| 2 |
title: len |
| 3 |
description: Returns the length of a string, slice, map, or collection. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: int |
| 10 |
signatures: [len VALUE] |
| 11 |
aliases: [/functions/len] |
| 12 |
--- |
| 13 |
|
| 14 |
With a string: |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ "ab" | len }} → 2 |
| 18 |
{{ "" | len }} → 0 |
| 19 |
``` |
| 20 |
|
| 21 |
With a slice: |
| 22 |
|
| 23 |
```go-html-template |
| 24 |
{{ slice "a" "b" | len }} → 2 |
| 25 |
{{ slice | len }} → 0 |
| 26 |
``` |
| 27 |
|
| 28 |
With a map: |
| 29 |
|
| 30 |
```go-html-template |
| 31 |
{{ dict "a" 1 "b" 2 | len }} → 2 |
| 32 |
{{ dict | len }} → 0 |
| 33 |
``` |
| 34 |
|
| 35 |
With a collection: |
| 36 |
|
| 37 |
```go-html-template |
| 38 |
{{ site.RegularPages | len }} → 42 |
| 39 |
``` |
| 40 |
|
| 41 |
You may also determine the number of pages in a collection with: |
| 42 |
|
| 43 |
```go-html-template |
| 44 |
{{ site.RegularPages.Len }} → 42 |
| 45 |
``` |
| 46 |
|
| 47 |
{{% include "/_common/functions/go-template/text-template.md" %}} |