Skip to main content

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.
info

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:

  1. Receives an array through the Array input
  2. Receives an index value through the Index input
  3. Validates that the array is not null
  4. Validates that the index is within valid bounds (0 to array length - 1)
  5. Retrieves the element at the specified index position
  6. 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:

  1. Array: ["John Smith", "Mary Johnson", "David Lee"]
  2. Index: 0
  3. Result: "John Smith"
  4. Use for processing the highest priority item

Example 2: Access Specific Search Result

Get a particular search result from scraped data:

  1. Array: {{msg.searchResults}} containing search result objects
  2. Index: {{msg.selectedIndex}} (e.g., 2 for the third result)
  3. Result: The third search result object
  4. Use for targeted data extraction

Example 3: Loop Through Array Elements

Access elements sequentially in a loop:

  1. Use a counter variable starting at 0
  2. Array: {{flow.dataItems}}
  3. Index: {{flow.counter}}
  4. Process the element
  5. Increment counter and repeat
  6. Continue until counter reaches array length

Example 4: Get Last Element (Dynamic Index)

Retrieve the last element using dynamic index calculation:

  1. Array: {{msg.items}}
  2. Get array length using Array.GetLength node → store in {{msg.length}}
  3. Calculate last index: {{msg.length - 1}}
  4. Index: {{msg.length - 1}}
  5. Result: Last element in the array

Example 5: Random Element Selection

Select a random element from an array:

  1. Array: ["Option A", "Option B", "Option C", "Option D"]
  2. Generate random number from 0 to (length-1) using JavaScript
  3. Index: Random number
  4. Result: Randomly selected element
  5. 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