Widgets/Transformer

Array Item Widget

Array Item Widget

A "Transformer" type widget. Array Item Widget extracts a single item from an array or string at a specified index position. It supports negative indices to count from the end, automatically detects the output data type, and indicates when no item is found. It's particularly useful for accessing specific elements in sequences or processing data item by item.

 

Inputs

  • in (DataType: Array, String, Anything) The array or string from which to extract an item. When using type Anything, the widget will work if the value is either an array or string.

Outputs

  • output (DataType: Automatically determined) The item found at the specified index. The data type is automatically determined based on the extracted item:

    • For strings: outputs a single character as String
    • For arrays: outputs the item with its original type (Number, String, Object, etc.)
  • noItem (DataType: Boolean) Outputs true when no item is found at the specified index (index out of bounds). Otherwise outputs false.


Custom Settings


Index Configuration

 

Examples

Working with Arrays

This example shows how to extract items from an array


Drag the example onto the workspace to explore and experiment!



In this example

  1. The Text widget provides the array as a JSON-formatted string, and the Text to Object widget parses it
  2. The Array Item widget is set to index 1 (second element, since indexing starts at 0)
  3. The Array Item widget:
    • Locates the item at index 1 ("banana")
    • Detects that it's a string value
    • Outputs "banana" through the "output" port
    • Outputs false through the "noItem" port (item was found)
  4. If the array changes but maintains the same length:
    • The Array Item widget will output the new item at index 1
    • The data type of the output adjusts automatically

 

Working with Strings

This example demonstrates extracting characters from a string


Drag the example onto the workspace to explore and experiment!



In this example

  1. The Text widget provides the string "Hello" through the "in" port
  2. The index is set to -1 (last position)
  3. The Array Item widget:
    • Converts -1 to the actual position (length - 1 = 4)
    • Extracts the character at that position ("o")
    • Outputs "o" through the "output" port
  4. Using negative indices with strings works the same as with arrays:
    • -1 gets the last character
    • -2 would get "l" (second to last)
    • -5 would get "H" (first character)

 

Handling Invalid Indices

This example shows what happens with an out-of-bounds index:


Drag the example onto the workspace to explore and experiment!



In this example

  1. The Text widget provides an array with 3 numbers as a JSON-formatted string, and the Text to Object widget parses it
  2. The parsed array is received through the "in" port of the Array Item widget
  3. The index is set to 5, but the array indices only range from 0 to 2
  4. The Array Item widget detects the invalid index and:
    • Does not transmit any value through the "output" port.
    • Transmits true through the "noItem" port.
  5. This same behavior occurs when:
    • The index is negative and beyond the array start (e.g., -4 for a 3-item array).
    • The index is larger than array length – 1.
    • The input is a string and the index is outside its length.

 

📌 Additional Notes

  • Index is 0-based (first item is at index 0)
  • Negative indices count from the end (-1 is last item, -2 is second to last, etc.)
  • The widget automatically detects the type of the extracted item
  • When the index is out of bounds:
    • The output port doesn't transmit a value
    • The noItem port transmits true
  • Works with any array type (numbers, strings, objects, mixed types)
  • For strings, each character is treated as an item

 

Glossary

  • 0-based index

    An indexing system where the first element is at position 0, the second at position 1, and so on. This is the standard indexing method used by most programming languages and the Array Item Widget.

  • Negative indices

    Index values that count backwards from the end of an array or string. For example, -1 refers to the last item, -2 to the second-to-last item, etc.

  • Out of bounds

    A condition that occurs when an index value is outside the valid range of an array or string. This happens when the index is negative beyond the start or exceeds the length minus one.