Description

Filters the key-value pairs in a struct.

Returns

Filtered struct.

Category

Syntax

structFilter(struct,function(key, value){return true|false;});

History

ColdFusion 10: Added this function.

Parameters

Parameter

Description

struct

Name of the struct object.

function

Inline function executed for each element in the array. Returns true if the key value pair in the struct has to be included in the resultant struct.

key

Key in a struct.

value

Value in a struct.

Example

<cfscript>
       myStruct={CF1=4.5,CF2=6,CF3=7,CF4=8,CF5=9,CF6=10,CF7=11,CF8=2016};
       WriteOutput("The input, unfiltered struct is:");
       WriteDump(myStruct);
       myFilteredStruct=StructFilter(myStruct,function(key,value){
             return value>8; //Return only those values >8
       }
       );
       WriteOutput("The filtered struct is:");
       WriteDump(myFilteredStruct);//Display the filtered struct
</cfscript>

Output

StructFilter

Using member function

<cfscript>
       myStruct={CF1=4.5,CF2=6,CF3=7,CF4=8,CF5=9,CF6=10,CF7=11,CF8=2016};
       CFVersions=myStruct.filter(function(key,value){
             return value>8;
       });
       WriteDump(CFVersions);
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy