githubEdit

StructFindKey

Searches a struct for a given key and returns an array of values

Method Signature

StructFindKey(struct=[structloose], key=[any], scope=[string])

Arguments

Argument
Type
Required
Description
Default

struct

struct

true

The struct to search

key

any

true

The key to search for

scope

string

false

Either one (default), which finds the first instance or all to return all values

one

Examples

Find first match for a nested struct key

Run Examplearrow-up-right

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( JSONSerialize( myKey ) );

Result: [{"path":".PERSON3.LASTNAME","owner":{"LASTNAME":"Harrison","FIRSTNAME":"George","ID":3},"value":"Harrison"}]

Find all matches of a nested struct key

Run Examplearrow-up-right

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"}]

Find first match for a nested struct key using member function

CF11+ calling the findKey member function on a struct.

Run Examplearrow-up-right

Result: [{"path":".PERSON3.LASTNAME","owner":{"LASTNAME":"Harrison","FIRSTNAME":"George","ID":3},"value":"Harrison"}]

Additional Examples

Run Examplearrow-up-right

Last updated

Was this helpful?