listFilter

Used to filter an list to items for which the closure function returns true.

listFilter(list, function(listElement, [list]) ) → returns string

Member Function Syntax

someList.listFilter(function(listElement, [list]) )

Argument Reference

list string
Required

function function
Required

Inline closure function executed for each element in the list. Returns true if the list element should be included in the filtered list. Support for passing the original list to the closure function added in CF11 Update 5.

Links more information about listFilter

Examples
Sample code invoking the listFilter function

Take list and use List Filter to return items that are 3 and higher.

numberList = '1,2,3,4,5,6';

threeOrMore = listFilter(numberList, function(item){
     return item >= 3;
});
writedump(threeOrMore);

Expected Result: A List with the values '3,4,5,6'

This is the same example as above, but using a member function on the list instead of a standalone function.

numberList = '1,2,3,4,5,6';

threeOrMore = numberList.listFilter(function(item){
     return item >= 3;
});
writedump(threeOrMore);

Expected Result: A List with the values '3,4,5,6'

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub