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 )
Name | Type | Required | Default | Description | Values | |
---|---|---|---|---|---|---|
top | any | Yes | CFML object (structure or array) from which to start search. This attribute requires an object, not a name of an object. |
|||
value | string | Yes | String or a variable that contains one for which to search. | |||
scope | string | Yes | * one: returns one matching key. Default. * all: returns all matching keys |
/Users/garethedwards/development/github/cfdocs/docs/functions/structfindkey.md | 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 ) );
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 ) );
CF11+ 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 ) );