Retrieves a single element from a list, based on its position.
Use ListGet when you need to pull one specific value out of a list variable - for example, grabbing the first item, the last item, or an item at a known position - rather than looping through the entire list.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
list |
List | Yes | The list variable you want to retrieve an element from. |
index |
Integer | Yes | The position of the element you want. Indexing starts at 1 (the first item is position 1, not 0). |
Returns
The value stored at the specified position in the list.
Example
If a list variable named Colors contains:
1: Red 2: Green 3: Blue
Then:
ListGet(Colors, 1) → Red ListGet(Colors, 3) → Blue
Things to keep in mind
-
1-based indexing: Unlike many programming languages that start counting at 0,
ListGettreats the first element as position1. This is a common source of off-by-one errors, so double-check your index value if results look shifted. -
Out-of-range positions: If you're not sure how many elements a list contains, use
ListSizefirst to check the count before callingListGet, so you avoid requesting a position that doesn't exist.
Related articles
- ListSize — get the number of elements in a list
- ListAdd — add an element to a list
- List Variables — general overview of working with lists
Comments
0 comments
Please sign in to leave a comment.