FILTER

Filters an array or an object by a lambda function or an array of values to keep.

If the target is an array, the lambda must take one argument: the value.

If the target is an object, the lambda can take one or two arguments. If the lambda takes one argument, the argument is the value. If the lambda takes two arguments, the first argument is the key and the second argument is the value.

Syntax 

FILTER(array | object, values_to_keep | LAMBDA(arg1, [arg2], expr))

Usage examples 

Example 1

Input

1
{
2
"my_array": [
3
1,
4
1,
5
2,
6
2,
7
3,
8
3
9
]
10
}

Formula

FILTER(my_array, ARRAY(2, 4))

Output

1
[
2
2,
3
2
4
]

Example 2

Input

1
{
2
"my_array": [
3
1,
4
2,
5
3,
6
4,
7
5,
8
6,
9
7,
10
8,
11
9,
12
10
13
]
14
}

Formula

FILTER(my_array, LAMBDA(item, item > 5))

Output

1
[
2
6,
3
7,
4
8,
5
9,
6
10
7
]

Example 3

Input

1
{
2
"my_object": {
3
"a": 1,
4
"b": 2,
5
"c": 3,
6
"d": 4,
7
"e": 5
8
}
9
}

Formula

FILTER(my_object, ARRAY(2, 4))

Output

1
{
2
"b": 2,
3
"d": 4
4
}

Example 4

If the target is an object and the lambda takes one argument, the argument is the value.

Input

1
{
2
"my_object": {
3
"a": 1,
4
"b": 2,
5
"c": 3,
6
"d": 4,
7
"e": 5
8
}
9
}

Formula

FILTER(my_object, LAMBDA(value, value > 2))

Output

1
{
2
"c": 3,
3
"d": 4,
4
"e": 5
5
}

Example 5

If the target is an object and the lambda takes two arguments, the first argument is the key and the second argument is the value.

Input

1
{
2
"my_object": {
3
"a": 1,
4
"b": 2,
5
"c": 3,
6
"d": 4,
7
"e": 5
8
}
9
}

Formula

FILTER(my_object, LAMBDA(key, value, key == 'a' || value > 3))

Output

1
{
2
"a": 1,
3
"d": 4,
4
"e": 5
5
}

Sample Actions 

Transform
FILTER
Transform
My Action

Select an action to inspect.

You can also click "Copy actions" and paste them in your Tines story to see how they work.

Was this helpful?