Extract a portion of an array based on specified start index and count
The Slice Block extracts a portion of an array. It takes an array as input and outputs a new array that starts at a specified index and contains a specified number of elements. This block is useful for manipulating arrays, such as extracting a subset of data from a larger dataset.
The array to be sliced.
The index at which to start the slice. Only available when “Use Start Input” is enabled.
The number of elements to include in the slice. Only available when “Use Count Input” is enabled.
The sliced array containing the extracted elements from the input array.
The index at which to start the slice. If not provided, defaults to 0.
The number of elements to include in the slice. If not provided, includes all elements from start to end.
When enabled, allows the start index to be provided via an input port instead of being set in the settings.
When enabled, allows the count to be provided via an input port instead of being set in the settings.
[1, 2, 3, 4, 5]
.Start
to 2
and the Count
to 2
.input
.output
should be [3, 4]
.input
is not provided or is not an arrayWhat happens if the Start is greater than the length of the array?
The Slice Block will return an empty array.
What happens if the Count is greater than the number of elements in the array?
The Slice Block will return all elements from the Start to the end of the array.
Can I use negative numbers for the Start and Count?
You can use negative numbers for the Start to count from the end of the array. However, using a negative number for the Count will result in an error.