Slice Node
Overview
The Slice Node is used to extract 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 node is useful for manipulating arrays, such as extracting a subset of data from a larger dataset.
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Input | any[] | The array to be sliced. | (required) | The input will be coerced into an array if it is not an array. |
Start | number | The index at which to start the slice. | 0 | The input will be coerced into a number if it is not a number. |
Count | number | The number of elements to include in the slice. If not provided, all elements will be included. | (all) | The input will be coerced into a number if it is not a number. This input is optional. |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Output | any[] | The sliced array. | The output will be an array containing the sliced elements from the input array. |
Editor Settings
Setting | Description | Default Value | Use Input Toggle | Input Data Type |
---|---|---|---|---|
Start | The index at which to start the slice. If not provided, the slice will start at the beginning. | 0 | Yes | number |
Count | The number of elements to include in the slice. If not provided, all elements will be included. | (all) | Yes | number |
Example 1: Slice an array
- Create an Array Node and set the values to
[1, 2, 3, 4, 5]
. - Create a Slice Node and set the
Start
to2
and theCount
to2
. - Connect the Array Node to the
Input
of the Slice Node. - Run the graph. The
Output
of the Slice Node should be[3, 4]
.
Error Handling
The Slice Node will error if the Input
is not provided or is not an array. It will also error if the Start
or Count
is not a number.
FAQ
Q: What happens if the Start
is greater than the length of the array?
A: The Slice Node will return an empty array.
Q: What happens if the Count
is greater than the number of elements in the array?
A: The Slice Node will return all elements from the Start
to the end of the array.
Q: Can I use negative numbers for the Start
and Count
?
A: Yes, 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.