Filter Node
Overview
The Filter Node is used to filter an array based on a corresponding array of boolean values. The node takes in an array of any data type and an array of boolean values of the same length. It then filters the array, only including the elements where the corresponding boolean value is true
.
This node is particularly useful when you want to filter an array based on some condition. For example, you could use a split (see Splitting) Compare Node to compare each element in an array to a value, and then use the Filter Node to filter the array based on the results of the comparison.
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Array | any[] | The array to be filtered. | (required) | The input will be coerced into an array if it is not an array. |
Include | boolean[] | An array of boolean values indicating whether to include each element in the array. | (required) | The input will be coerced into a boolean array if it is not a boolean array. The length of this array should match the length of the Array input. |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Filtered | any[] | The filtered array, containing only the elements where the corresponding boolean value in the Include input was true . | The output will be an array of the same data type as the Array input. If the Array input is not an array, the output will be an array of any . |
Editor Settings
This node has no configurable editor settings.
Example 1: Filter an array of numbers
- Create an Array Node and set the values to
[1, 2, 3, 4, 5]
. - Create another Array Node and set the values to
[true, false, true, false, true]
. - Create a Filter Node and connect the first Array Node to the
Array
input and the second Array Node to theInclude
input. - Run the graph. The
Filtered
output of the Filter Node should be[1, 3, 5]
.
Example 2: Filter an array based on a condition
- Create an Array Node and set the values to
[1, 2, 3, 4, 5]
. - Create a Compare Node and set the comparison to
>
. Enable splitting on the Compare node. - Create a Number Node and set the value to
3
. - Connect the Array Node to the
A
input of the Compare Node, and connect the Number Node to theB
input of the Compare Node. - Create a Filter Node and connect the Compare Node to the
Array
input and theResult
output of the Compare Node to theInclude
input. - Run the graph. The
Filtered
output of the Filter Node should be[4, 5]
.
Error Handling
The Filter Node will error if the Array
or Include
inputs are not provided, or if the lengths of the arrays do not match.
FAQ
Q: What happens if the lengths of the Array and Include inputs do not match?
A: The Filter Node will error. The lengths of the Array and Include inputs should always match.
Q: Can I use the Filter Node to filter an array of objects?
A: Yes, you can use the Filter Node to filter an array of any data type, including objects. Just make sure to provide an array of boolean values indicating whether to include each object in the filtered array.