StructFilter()
This function creates a new Struct that returns all entries from an struct that match the given filter.
StructFilter( struct=struct, filter=function, parallel=boolean, maxThreads=number );
Returns: Struct
Examples
Non-Member Function
animals = {
cow: "moo",
pig: "oink",
snail: ""
};
// Show all animals
Dump(
label: "All animals",
var: animals
);
// Get animals that make noise
noisyAnimals = StructFilter(animals, function(key) {
// If the key has a value return true (noisy animal)
if (Len(animals[arguments.key])) {
return true;
}
<span class="nv">return</span> <span class="nv">false</span><span class="p">;</span>
});
Dump(
label: "Noisy Animals",
var: noisyAnimals
);
// Get animals that are quiet
quietAnimals = StructFilter(animals, function(key) {
// If the key has a value return true (quiet animal)
if (! Len(animals[arguments.key])) {
return true;
}
<span class="nv">return</span> <span class="nv">false</span><span class="p">;</span>
});
Dump(
label: "Quiet Animals",
var: quietAnimals
);
See also
- Structures
- Collections
- struct.filter()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)