{
"name":"arrayFilter",
"type":"function",
"syntax":"arrayFilter(array, function(item [,index, array]){} [, parallel] [, maxThreads])",
"member":"someArray.filter(function(item [,index, array]){} [, parallel] [, maxThreads])",
"returns":"array",
"related":["arrayEach", "arraySome","ArrayMap","arrayReduce"],
"description":"Used to filter an array to items for which the closure function returns true.",
"params": [
{"name":"array","description":"","required":true,"default":"","type":"array","values":[]},
{"name":"callback","description":"Closure or a function reference that will be called for each of the iteration. Returns true if the array element should be included in the filtered array. Support for passing the original array to the closure function added in CF11 Update 5.",
"callback_params": [
{
"values": [],
"default": "",
"description": "The value for the current iteration",
"name": "value",
"type": "any",
"required": false
},{
"values": [],
"default": "",
"description": "The current index for the iteration",
"name": "index",
"type": "numeric",
"required": false
},{
"values": [],
"default": "",
"description": "A reference of the original array",
"name": "array",
"type": "array",
"required": false
}],"type":"boolean","required":true,"values":[],"default":""},
{"name":"parallel","description":"Lucee4.5+ true if the items can be executed in parallel","required":false,"default":"false","type":"boolean","values":[true, false]},
{"name":"maxThreads","description":"Lucee4.5+ the maximum number of threads to use when parallel = true","required":false,"default":"20","type":"numeric","values":[]}
],
"engines": {
"coldfusion": {"minimum_version":"10", "notes":"", "docs":"https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-a-b/arrayfilter.html"},
"lucee": {"minimum_version":"", "notes":"", "docs":"https://docs.lucee.org/reference/functions/arrayfilter.html"},
"openbd": {"minimum_version":"", "notes":"", "docs":"http://openbd.org/manual/?/function/arrayfilter"},
"boxlang": {"minimum_version":"1.0.0", "notes":"", "docs":"https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/array/arrayfilter"}
},
"links":[{
"title":"Map, Reduce and other Higher Order Functions",
"description":"A Primer for map, reduce, filter, and Higher Order Functions in general.",
"url":"http://ryanguill.com/functional/higher-order-functions/2016/05/18/higher-order-functions.html"
},
{
"title": "ColdFusion 11: .map() and .reduce()",
"description": "A look at the new .map() and .reduce() methods that each of array, struct and lists all have",
"url":"http://blog.adamcameron.me/2014/02/coldfusion-11-map-and-reduce.html"
}],
"examples": [
{
"title": "Simple numeric comparison",
"description": "Take an array of struct items and use arrayFilter to return ones of a rating 3 and higher.",
"code": "fruitArray = [{'fruit'='apple', 'rating'=4}, {'fruit'='banana', 'rating'=1}, {'fruit'='orange', 'rating'=5}, {'fruit'='mango', 'rating'=2}, {'fruit'='kiwi', 'rating'=3}];\n\nfavoriteFruits = arrayFilter(fruitArray, function(item){\n\treturn item.rating >= 3;\n});\nwritedump(serializeJSON(favoriteFruits));",
"result": "[{\"fruit\":\"apple\",\"rating\":4},{\"fruit\":\"orange\",\"rating\":5},{\"fruit\":\"kiwi\",\"rating\":3}]"
},
{
"title": "Using a member function",
"description": "This is the same example as above, but using a member function on the array instead of a standalone function.",
"code": "fruitArray = [{'fruit'='apple', 'rating'=4}, {'fruit'='banana', 'rating'=1}, {'fruit'='orange', 'rating'=5}, {'fruit'='mango', 'rating'=2}, {'fruit'='kiwi', 'rating'=3}];\n\nfavoriteFruits = fruitArray.filter(function(item){\n\treturn item.rating >= 3;\n});\nwritedump(serializeJSON(favoriteFruits));",
"result": "[{\"fruit\":\"apple\",\"rating\":4},{\"fruit\":\"orange\",\"rating\":5},{\"fruit\":\"kiwi\",\"rating\":3}]"
}
]
}