StructGet

Retrieves the value from a struct using a path based expression

Method Signature

StructGet(path=[string])

Arguments

Argument
Type
Required
Description
Default

path

string

true

The string path to the object requested in the struct

Examples

Get a value in a structure using structGet

Run Example

x = { 
	Y : {
		Z : 8
	}
};
writeDump( structGet( "x.y.z" ) );

Result: 8

Accidentally Modifying a Structure

The structGet function will modify the variable x by adding a new structure x.a and also adds a key x.a.b to satisfy the path.

Run Example

x = { 
	Y : {
		Z : 8
	}
};
writeDump( structGet( "x.a.b" ) );
writeDump( x );

Accidentally Overwriting a variable using structGet

The value of x.y.z[2] will be set to an empty struct.

Run Example

x = { 
	Y : {
		Z : [
			1,
			2,
			3
		]
	}
};
writeDump( structGet( "x.y.z[2]" ) );
writeDump( x );

Additional Examples

Run Example

animals = { 
	CAT : {
		ACTIVITIES : {
			SLEEP : true,
			EAT : true,
			DRINK : true
		}
	}
};
// Show all animals
Dump( label="All animals", var=animals );
// Get cat activities in animals
getCatActivities = StructGet( "animals.cat.activities" );
// Show results of getCatActivities
Dump( label="Results of StructGet(""animals.cat.activities"")", var=getCatActivities );
// If the path does not exist, result returns an empty structure.
findDog = StructGet( "animals.dog" );
// Show results of findDog
Dump( label="Results of StructGet(""animals.dog"")", var=findDog );

Last updated

Was this helpful?