From 6408533fcabbb689a460026591f8afa85f233839 Mon Sep 17 00:00:00 2001 From: craiggenner Date: Thu, 22 Oct 2020 19:03:27 +0100 Subject: [PATCH] The index must be non-negative integer and added instructions on how to get the last value in the list. --- website/docs/configuration/functions/element.html.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/website/docs/configuration/functions/element.html.md b/website/docs/configuration/functions/element.html.md index c4f85d9e4..8c8fa4f74 100644 --- a/website/docs/configuration/functions/element.html.md +++ b/website/docs/configuration/functions/element.html.md @@ -19,7 +19,7 @@ element(list, index) ``` The index is zero-based. This function produces an error if used with an -empty list. +empty list. The index must be non-negative integer. Use the built-in index syntax `list[index]` in most cases. Use this function only for the special additional "wrap-around" behavior described below. @@ -39,6 +39,15 @@ If the given index is greater than the length of the list then the index is a ``` +To get the last element from the list use [`length`](./length.html) to find +the size of the list (minus 1 as the list is zero-based) and then pick the +last element: + +``` +> element(["a", "b", "c"], length(["a", "b", "c"])-1) +c +``` + ## Related Functions * [`index`](./index.html) finds the index for a particular element value.