[9,2,3,4,5] filter (value, index) -> (value > 2)
filter
filter(Array<T>, (item: T, index: Number) -> Boolean): Array<T>
Iterates over an array and applies an expression that returns matching values.
The expression must return true or false. If the expression returns true
for a value or index in the array, the value gets captured in the output array.
If it returns false for a value or index in the array, that item gets
filtered out of the output. If there are no matches, the output array will
be empty.
Parameters
| Name | Description |
|---|---|
|
The array to filter. |
|
Boolean expression that selects an |
Example
This example returns an array of all items found at an index ($$)
greater than 1 where the value of the element is less than 5. Notice that
it is using anonymous parameters as selectors instead of using named
parameters in an anonymous function.
Example
This example reads a JSON array that contains objects with user and error keys, and uses the filter function to return only the objects in which the value of the error key is null.
Example
This example reads a JSON array and uses the filter function to extract the phone numbers that are active.
Input
{
"Id": "1184001100000000517",
"marketCode": "US",
"languageCode": "en-US",
"profile": {
"base": {
"username": "TheMule",
"activeInd": "R",
"phone": [
{
"activeInd": "Y",
"type": "mobile",
"primaryInd": "Y",
"number": "230678123"
},
{
"activeInd": "N",
"type": "mobile",
"primaryInd": "N",
"number": ""
},
{
"activeInd": "Y",
"type": "mobile",
"primaryInd": "Y",
"number": "154896523"
}
]
}
}
}



