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

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