Used to filter the key-value pairs in a structure.
structFilter(struct,function(key, value [,struct]){} [, parallel] [, maxThreads])
→ returns struct
someStruct.filter(function(key, value [,struct]){} [, parallel] [, maxThreads])
key
*
string
:
The key for the current iteration
value
*
any
:
The value for the current iteration
struct
*
struct
:
A reference of the original struct
false
true
false
20
Take a struct of items with their rating and use structFilter to return ones of a rating 3 and higher.
fruitRatings = {apple=4,banana=1,orange=5,mango=2,kiwi=3};
favoriteFruits = structFilter(fruitRatings, function(key, value){
return value >= 3;
});
writedump(favoriteFruits);
Expected Result: {apple=4,orange=5,kiwi=3}
This is the same example, but using a member function on the struct instead of a standalone function.
fruitRatings = {apple=4,banana=1,orange=5,mango=2,kiwi=3};
favoriteFruits = fruitRatings.filter(function(key, value){
return value >= 3;
});
writedump(favoriteFruits);
Expected Result: {apple=4,orange=5,kiwi=3}
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.