StructUpdate

Updates or sets a key/value pair in to a struct

Method Signature

StructUpdate(struct=[modifiableStruct], key=[any], value=[any])

Arguments

Argument
Type
Required
Description
Default

struct

modifiableStruct

true

The target struct

key

any

true

The struct key

value

any

true

The value to assign for the specified key

Examples

Updates a structure value at specific key

Change value of structure item

Run Example

myStruct = { 
	A : 1,
	B : 2,
	C : 3,
	D : 4
};
structUpdate( myStruct, "c", 15 );
writeDump( JSONSerialize( myStruct ) );

Result: {"A":1,"B":2,"C":15,"D":4}

Additional Examples

Run Example

animals = { 
	COW : "moo",
	PIG : "oink",
	CAT : "meow"
};
// Show current animals
Dump( label="Current animals", var=animals );
// Update cat in animals
StructUpdate( animals, "cat", "purr" );
// Show animals with updated cat in animals
Dump( label="Animals with cat updated", var=animals );

Last updated

Was this helpful?