Index Block
Retrieve values from an array at specified indices
Overview
The Index Block allows you to retrieve values from an array at specified indices. It can return a single value when given a single index or multiple values when provided with an array of indices. This block is particularly useful for extracting specific elements from arrays or for reordering array elements based on a set of indices.
Key Features
- Retrieve a single value at a specified index
- Extract multiple values using an array of indices
- Supports negative indices for accessing elements from the end of the array
- Option to invert the selection to get all values except those at specified indices
Inputs
The input array from which to retrieve values.
The index or array of indices to retrieve. Can be a single number or an array of numbers.
Outputs
The value(s) retrieved from the input array at the specified index/indices. If a single index is provided or only one value is selected, this will be a single value. If multiple indices are provided, this will be an array of values. If no values are selected, this output will be control-flow-excluded.
Editor Settings
When enabled, inverts the selection to return all values except those at the specified indices.
Example: Extracting Specific Elements from an Array
- Create an Array Block with values
[10, 20, 30, 40, 50]
. - Add an Index Block and connect the Array Block to its
array
input. - Create a Number Block with value
2
(or an Array Block with values[0, 2, 4]
) and connect it to the Index Block’sindicies
input. - Run the flow. The Index Block’s
output
will be30
(or[10, 30, 50]
if using an array of indices).
Error Handling
- If an index is out of range (less than 0 or greater than array length), the block will throw an error
- If the array input is not an array, the block will throw an error
- If no values are selected, the output will be control-flow-excluded