github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/collection/slice.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: slice - Functions - Configuration Language
     4  description: The slice function extracts some consecutive elements from within a list.
     5  ---
     6  
     7  # `slice` Function
     8  
     9  `slice` extracts some consecutive elements from within a list.
    10  
    11  ```hcl
    12  slice(list, startindex, endindex)
    13  ```
    14  
    15  `startindex` is inclusive, while `endindex` is exclusive. This function returns
    16  an error if either index is outside the bounds of valid indices for the given
    17  list.
    18  
    19  ## Examples
    20  
    21  ```shell-session
    22  > slice(["a", "b", "c", "d"], 1, 3)
    23  [
    24    "b",
    25    "c",
    26  ]
    27  ```
    28  
    29  ## Related Functions
    30  
    31  - [`substr`](/docs/job-specification/hcl2/functions/string/substr) performs a similar function for characters in a
    32    string, although it uses a length instead of an end index.