2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
title: len
|
2023-05-22 10:43:12 -04:00
|
|
|
description: Returns the length of a string, slice, map, or collection.
|
2023-12-04 09:14:18 -05:00
|
|
|
categories: []
|
2023-10-20 03:42:39 -04:00
|
|
|
keywords: []
|
2023-12-04 09:14:18 -05:00
|
|
|
action:
|
2023-10-20 03:42:39 -04:00
|
|
|
aliases: []
|
2023-12-04 09:14:18 -05:00
|
|
|
related:
|
|
|
|
- functions/strings/Count
|
|
|
|
- functions/strings/CountRunes
|
|
|
|
- functions/strings/CountWords
|
|
|
|
- functions/strings/RuneCount
|
2023-10-20 03:42:39 -04:00
|
|
|
returnType: int
|
2023-12-04 09:14:18 -05:00
|
|
|
signatures: [len VALUE]
|
2023-10-20 03:42:39 -04:00
|
|
|
aliases: [/functions/len]
|
2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
With a string:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ "ab" | len }} → 2
|
|
|
|
{{ "" | len }} → 0
|
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
With a slice:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ slice "a" "b" | len }} → 2
|
|
|
|
{{ slice | len }} → 0
|
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
With a map:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ dict "a" 1 "b" 2 | len }} → 2
|
|
|
|
{{ dict | len }} → 0
|
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
With a collection:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ site.RegularPages | len }} → 42
|
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
You may also determine the number of pages in a collection with:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ site.RegularPages.Len }} → 42
|
|
|
|
```
|
2023-12-04 09:14:18 -05:00
|
|
|
|
|
|
|
{{% include "functions/go-template/_common/text-template.md" %}}
|