StructKeyExists

Tests whether a key exists in a struct and returns a boolean value

Method Signature

StructKeyExists(struct=[structloose], key=[any])

Arguments

Argument
Type
Required
Description
Default

struct

struct

true

The struct to test

key

any

true

The key within the struct to test for existence

Examples

Check if server struct has OS key

Run Example

structKeyExists( server, "os" );

Result: true

Check if server struct has OS key using member function

CF11+ calling the keyExists member function on a struct.

Run Example

server.keyExists( "os" );

Result: true

Additional Examples

Run Example

animals = { 
	COW : "moo",
	PIG : "oink",
	CAT : "meow",
	BIRD : "chirp"
};
// Check to see if key exists in struct
if( StructKeyExists( animals, "snail" ) ) {
	echo( "There is a snail in 'animals'" );
}
 else {
	echo( "No snail exists in 'animals'" );
}

Last updated

Was this helpful?