Skip to main content

Filter Node

Filter Node Screenshot

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

TitleData TypeDescriptionDefault ValueNotes
Arrayany[]The array to be filtered.(required)The input will be coerced into an array if it is not an array.
Includeboolean[]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.

Example 1: Filter an array of numbers

  1. Create an Array Node and set the values to [1, 2, 3, 4, 5].
  2. Create another Array Node and set the values to [true, false, true, false, true].
  3. Create a Filter Node and connect the first Array Node to the Array input and the second Array Node to the Include input.
  4. Run the graph. The Filtered output of the Filter Node should be [1, 3, 5].

Filter Node Example 1

Example 2: Filter an array based on a condition

  1. Create an Array Node and set the values to [1, 2, 3, 4, 5].
  2. Create a Compare Node and set the comparison to >. Enable splitting on the Compare node.
  3. Create a Number Node and set the value to 3.
  4. Connect the Array Node to the A input of the Compare Node, and connect the Number Node to the B input of the Compare Node.
  5. Create a Filter Node and connect the Compare Node to the Array input and the Result output of the Compare Node to the Include input.
  6. Run the graph. The Filtered output of the Filter Node should be [4, 5].

Filter Node Example 2

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.

See Also