Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

filterObject

filterObject({ (K)?: V }, (value: V, key: K, index: Number) → Boolean): { (K)?: V }

Returns an object that filters an input object based on a matching condition.

The function (a lambda) is invoked with three parameters: value, key, and index. If these parameters are not named, the value is defined by default as $, the key $$ and the index $$$.

This example filters an object by its value.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
{'letter1': 'a', 'letter2': 'b'} filterObject ((value1) -> value1 == 'a')
Output

        
     
1
2
3
{
  'letter1': 'a'
}

You can produce the same results with this input:

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
{'letter1': 'a', 'letter2': 'b'} filter ($ == 'a')
filterObject(Null, (value: Nothing, key: Nothing, index: Nothing) → Boolean): Null

Helper function that allows filterObject to work with null values.