Get Element
Retrieves a single element from an array by its index position.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Array - The array to retrieve an element from.
- Index - The zero-based index position of the element to retrieve (0 = first element, 1 = second element, etc.).
Outputs
- Element - The element at the specified index position.
How It Works
The Get Element node retrieves a specific element from an array using its index. When executed, the node:
- Receives an array through the Array input
- Receives an index value through the Index input
- Validates that the array is not null
- Validates that the index is within valid bounds (0 to array length - 1)
- Retrieves the element at the specified index position
- Returns the element through the Element output
Requirements
- Valid array as input (not null)
- Valid index value (must be 0 or greater and < array length)
Error Handling
The node will return specific errors in the following cases:
- Array is null: "Array cannot be null"
- Index is negative: "Index cannot be less than 0"
- Index is too large: "Index X cannot be larger than the array length Y"
Array Indexing
Arrays use zero-based indexing:
- First element: index 0
- Second element: index 1
- Last element: index = (array length - 1)
Example: For array ["apple", "banana", "orange"]:
- Index 0 returns "apple"
- Index 1 returns "banana"
- Index 2 returns "orange"
- Index 3 causes an error (out of bounds)
Usage Examples
Example 1: Get First Customer from List
Retrieve the first customer for priority processing:
- Array:
["John Smith", "Mary Johnson", "David Lee"] - Index:
0 - Result:
"John Smith" - Use for processing the highest priority item
Example 2: Access Specific Search Result
Get a particular search result from scraped data:
- Array:
{{msg.searchResults}}containing search result objects - Index:
{{msg.selectedIndex}}(e.g., 2 for the third result) - Result: The third search result object
- Use for targeted data extraction
Example 3: Loop Through Array Elements
Access elements sequentially in a loop:
- Use a counter variable starting at 0
- Array:
{{flow.dataItems}} - Index:
{{flow.counter}} - Process the element
- Increment counter and repeat
- Continue until counter reaches array length
Example 4: Get Last Element (Dynamic Index)
Retrieve the last element using dynamic index calculation:
- Array:
{{msg.items}} - Get array length using Array.GetLength node → store in
{{msg.length}} - Calculate last index:
{{msg.length - 1}} - Index:
{{msg.length - 1}} - Result: Last element in the array
Example 5: Random Element Selection
Select a random element from an array:
- Array:
["Option A", "Option B", "Option C", "Option D"] - Generate random number from 0 to (length-1) using JavaScript
- Index: Random number
- Result: Randomly selected element
- Use for random selection or testing scenarios
Tips for Effective Use
- Remember zero-based indexing: First element is at index 0, not 1
- Use Array.GetLength to determine the maximum valid index (length - 1)
- For dynamic indexing in loops, maintain a counter variable
- Combine with conditional logic to handle different array positions
- Use with Array.GetLength to validate index before accessing
- The element can be any data type: string, number, object, array, or boolean
- For accessing multiple elements, consider using Array.Slice instead
- Use in loops to iterate through all array elements sequentially
Common Use Cases
- Accessing the first or last element in a list
- Sequential processing of array elements in a loop
- Retrieving specific records from query results
- Selecting items based on position (e.g., top result, second choice)
- Random element selection from a list
- Accessing nested data structures by combining with JSON nodes
- Processing prioritized items (first in array = highest priority)
- Implementing queue behavior (first element = next to process)
Common Errors and Solutions
Error: "Index cannot be less than 0"
Cause: The index value is negative.
Solutions:
- Ensure index variables are initialized with valid values (0 or greater)
- Add validation to prevent negative indices
- Check loop counter initialization
Error: "Index X cannot be larger than the array length Y"
Cause: The index exceeds the maximum valid position in the array.
Solutions:
- Use Array.GetLength to determine array size before accessing elements
- Add validation:
if (index < arrayLength) then access element - For last element, use index = (length - 1), not length
- Check loop termination conditions to prevent exceeding array bounds
Error: "Array cannot be null"
Cause: The array input is null or undefined.
Solutions:
- Verify that the array variable is properly initialized
- Check that previous nodes successfully created/populated the array
- Use conditional logic to check array existence before accessing elements
- Initialize empty arrays with Array.Assign if needed