ArrayFilter()
This function creates a new Array that returns all the values from an array that match the given filter.
ArrayFilter( array=array, filter=function, parallel=boolean, maxThreads=number );
Returns: Array
Examples
filter an array by its values
fruitArray = [{fruit='apple', rating=4}, {fruit='banana', rating=1}, {fruit='orange', rating=5}, {fruit='mango', rating=2}, {fruit='kiwi', rating=3}];
favoriteFruits = arrayFilter(fruitArray, function(item){
return item.rating >= 3;
});
dump(favoriteFruits);
filter an array by its values (member function)
fruitArray = [{fruit='apple', rating=4}, {fruit='banana', rating=1}, {fruit='orange', rating=5}, {fruit='mango', rating=2}, {fruit='kiwi', rating=3}];
favoriteFruits = fruitArray.filter(function(item){
return item.rating >= 3;
});
dump(favoriteFruits);
See also
- Arrays
- Collections
- Threads
- array.filter()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)