github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/collection/length.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: length - Functions - Configuration Language
     4  sidebar_title: length
     5  description: The length function determines the length of a collection or string.
     6  ---
     7  
     8  # `length` Function
     9  
    10  `length` determines the length of a given list, map, or string.
    11  
    12  If given a list or map, the result is the number of elements in that collection.
    13  If given a string, the result is the number of characters in the string.
    14  
    15  ## Examples
    16  
    17  ```shell-session
    18  > length([])
    19  0
    20  > length(["a", "b"])
    21  2
    22  > length({"a" = "b"})
    23  1
    24  > length("hello")
    25  5
    26  ```
    27  
    28  When given a string, the result is the number of characters, rather than the
    29  number of bytes or Unicode sequences that form them:
    30  
    31  ```shell-session
    32  > length("👾🕹️")
    33  2
    34  ```
    35  
    36  A "character" is a _grapheme cluster_, as defined by
    37  [Unicode Standard Annex #29](http://unicode.org/reports/tr29/). Note that
    38  remote APIs may have a different definition of "character" for the purpose of
    39  length limits on string arguments; a Nomad provider is responsible for
    40  translating Nomad's string representation into that used by its respective
    41  remote system and applying any additional validation rules to it.