diff --git a/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx b/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx index f58c7b8f3..7ab775319 100644 --- a/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx +++ b/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx @@ -1,25 +1,30 @@ --- layout: docs page_title: index - Functions - Configuration Language -description: The index function finds the element index for a given value in a list. +description: |- + The index function returns an element from the given list or map + using the given index or key. --- # `index` Function -`index` finds the element index for a given value in a list. +`index` finds the element at the index when handling lists, or the element at +the key when handling maps. ```hcl index(list, value) ``` -The returned index is zero-based. This function produces an error if the given -value is not present in the list. - ## Examples ```shell-session -> index(["a", "b", "c"], "b") -1 +> index(["a", "b", "c"], 1) +"b" +``` + +```shell-session +> index({"a"=1, "c"=2, "d"=3}, "c") +2 ``` ## Related Functions