filter

utility

Filters array elements by condition

Syntax

filter(array, condition)

Parameters

array (array)

The array to filter (implicit when used in pipeline)

condition (expression)

Boolean expression to filter by

Returns

array

Filtered array containing only matching elements

Examples

Filter adults only
Input:
filter(.age > 18)
Output:
[{name: "Alice", age: 30}, {name: "Bob", age: 25}]
Filter active users
Input:
filter(.status == "active")
Output:
[{name: "Alice", status: "active"}]

The filter() function returns only the array elements that match a specified condition.

Usage

Use filter() to select rows from DataFrames or elements from arrays that meet specific criteria.

Related Functions