Searches recursively through a substructure of nested arrays,
structures, and other elements, for structures whose keys
match the search key in the value parameter.
structFindKey(top, value, scope)
→ returns array
struct.findKey( value, scope )
one
all
Beatles = {
person1: { id: 1, firstName: 'John', lastName: 'Lennon' },
person2: { id: 2, firstName: 'Paul', lastName: 'McCartney' },
person3: { id: 3, firstName: 'George', lastName: 'Harrison' },
person5: { id: 5, firstName: 'Abbey', lastName: 'Road' },
person4: { id: 4, firstName: 'Ringo', lastName: 'Starr' }
};
myKey = structFindKey( Beatles, 'lastName', 'one' );
writeOutput( serializeJSON( myKey ) );
Expected Result: [{"path":".PERSON3.LASTNAME","owner":{"LASTNAME":"Harrison","FIRSTNAME":"George","ID":3},"value":"Harrison"}]
Beatles = {
person1: { id: 1, firstName: 'John', lastName: 'Lennon' },
person2: { id: 2, firstName: 'Paul', lastName: 'McCartney' },
person3: { id: 3, firstName: 'George', lastName: 'Harrison' },
person4: { id: 4, firstName: 'Ringo', lastName: 'Starr' }
};
myKey = structFindKey( Beatles, 'lastName', 'all' );
writeOutput( serializeJSON( myKey ) );
Expected Result: [{"path":".PERSON3.LASTNAME","owner":{"LASTNAME":"Harrison","FIRSTNAME":"George","ID":3},"value":"Harrison"},{"path":".PERSON1.LASTNAME","owner":{"LASTNAME":"Lennon","FIRSTNAME":"John","ID":1},"value":"Lennon"},{"path":".PERSON2.LASTNAME","owner":{"LASTNAME":"McCartney","FIRSTNAME":"Paul","ID":2},"value":"McCartney"},{"path":".PERSON4.LASTNAME","owner":{"LASTNAME":"Starr","FIRSTNAME":"Ringo","ID":4},"value":"Starr"}]
CF 11+ calling the findKey member function on a struct.
Beatles = {
person1: { id: 1, firstName: 'John', lastName: 'Lennon' },
person2: { id: 2, firstName: 'Paul', lastName: 'McCartney' },
person3: { id: 3, firstName: 'George', lastName: 'Harrison' },
person5: { id: 5, firstName: 'Abbey', lastName: 'Road' },
person4: { id: 4, firstName: 'Ringo', lastName: 'Starr' }
};
myKey = Beatles.findKey( 'lastName', 'one' );
writeOutput( serializeJSON( myKey ) );
Expected Result: [{"path":".PERSON3.LASTNAME","owner":{"LASTNAME":"Harrison","FIRSTNAME":"George","ID":3},"value":"Harrison"}]
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.