Skip to content

length

统计字符串字符数、数组条目数或对象键数。

语法

knap
{{ value | length }}

示例

数组长度

Data
json
{
  "tags": [
    "notes",
    "ideas",
    "books"
  ]
}
Template
knap
{{ tags | length }}
Output
md
3

字符串长度

Data
json
{
  "title": "Knap"
}
Template
knap
{{ title | length }}
Output
md
4

对象长度

Data
json
{
  "author": {
    "name": "Ada",
    "role": "Writer"
  }
}
Template
knap
{{ author | length }}
Output
md
2