Get Array Item
Get Array Item node is designed to extract a specific item from an array based on its index. This node is particularly useful when you need to access a particular element within an array for further processing or output in your workflow.
Properties Panel
Field
Description
Required
Node name
true
Variable Name
The name of the variable where the extracted item will be stored
true
Item Index
The index of the item to be extracted from the array (0-based)
-len(arr) <= i < len(arr)
true
Lookup Array
The array from which the item will be extracted
true
Usage
Specify a variable name where the extracted item will be stored.
Enter the index value of the item you want to extract (remember that array indices start at 0).
Provide the lookup array from which the item will be extracted.
Returns
The node stores the extracted item in the specified variable. You can access this using Magical Autocomplete (e.g., $.variables.<variable_name>
) in any node below this node.
Example
Let's say you have an array of user objects fetched from database using List Records node and you want to extract the second user:
Set Variable name to
second_user
Set Index value to 1 (remember, arrays are 0-indexed)
Set Lookup array to
$.listRecords.result
(assuming you're usingList Records
node and it's name islistRecords
)
This will store the second user object in the variable second_user
. You can then use this in subsequent nodes by $.variables.second_user
Best Practices
Always ensure that the index value is within the bounds of the array. Attempting to access an out-of-bounds index may result in an error.
Negative Index are supported for extracting values from back but make sure it's within the size of lookup-array.
Remember that array indices start at 0, so the first item is at index
0
, the second at index1
, and so on.If you need to access the last item in an array of unknown length, you can use
-1
as index value.When working with potentially empty arrays, consider adding a condition to check the array length before attempting to extract an item.
Last updated