structFindValue

Searches recursively through a substructure of nested arrays,
structures, and other elements for structures with values that
match the search key in the value parameter.

structFindValue(top, value [, scope]) → returns array

Member Function Syntax

struct.findValue( value, scope )

structFindValue Argument Reference

top any
Required

CFML object (a structure or an array) from which to
start search. This attribute requires an object, not a
name of an object.

value string
Required

String or a variable that contains one for which to search.
The type must be a simple object. Arrays and structures
are not supported.

scope string

one: function returns one matching key (default)
all: function returns all matching keys
Values:
  • one
  • all

Examples sample code invoking the structFindValue function

myStruct = { a=2, b=4, c=8, d=10, e=12, f=12 };
myStruct.mySecondStruct = { a1=50, a2=12 };
myStruct.mySecondStruct.myThirdStruct = { b1=12, b2=65 };
myValue=StructFindValue( myStruct, "12", "one" );
WriteOutput( serializeJSON( myValue ) );

Expected Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"}]

myStruct = { a=2, b=4, c=8, d=10, e=12, f=12 };
myStruct.mySecondStruct = { a1=50, a2=12 };
myStruct.mySecondStruct.myThirdStruct = { b1=12, b2=65 };
myValue=StructFindValue( myStruct, "12", "all" );
WriteOutput( serializeJSON( myValue ) );

Expected Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"},{"path":".F","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"F"},{"path":".MYSECONDSTRUCT.A2","owner":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}},"key":"A2"},{"path":".MYSECONDSTRUCT.MYTHIRDSTRUCT.B1","owner":{"B2":65,"B1":12},"key":"B1"}]

CF 11+ calling the findValue member function on a struct.

myStruct = { a=2, b=4, c=8, d=10, e=12, f=12 };
myStruct.mySecondStruct = { a1=50, a2=12 };
myStruct.mySecondStruct.myThirdStruct = { b1=12, b2=65 };
myValue=myStruct.findValue( "12", "one" );
WriteOutput( serializeJSON( myValue ) );

Expected Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"}]


Fork me on GitHub