array.filter() function
array.filter()
iterates over an array, evaluates each element with a predicate function, and then returns
a new array with only elements that match the predicate.
Function type signature
(<-arr: [A], fn: (x: A) => bool) => [A]
Parameters
arr
Array to filter. Default is the piped-forward array (<-
).
fn
(Required)
Predicate function to evaluate on each element.
The element is represented by x
in the predicate function.
Examples
Filter array of integers
import "array"
a = [
1,
2,
3,
4,
5,
]
b = a |> array.filter(fn: (x) => x >= 3)
// b returns [3, 4, 5]
// Output the filtered array as a table
array.from(rows: b |> array.map(fn: (x) => ({_value: x})))
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.