ArrayToStruct

Transform the array to a struct, the index of the array is the key of the struct

Method Signature

ArrayToStruct(array=[array])

Arguments

Argument
Type
Required
Description
Default

array

array

true

The array to convert

Examples

Convert an array to a struct using arrayToStruct()

Run Example

JSONSerialize( arrayToStruct( [ 
	"a",
	"b"
] ) );

Result: {"1":"a","2":"b"}

Additional Examples

arr = [ 
	"a",
	"b",
	"c",
	"d",
	"e",
	"f",
	"g"
];
dump( arrayToStruct( arr ) );
if( listFirst( server.BOXLANG.VERSION, "." ) >= 6 ) dump( arrayToStruct( arr, true ) );
// member function
dump( arr.toStruct() );

Run Example

arr = [ 
	{
		NAME : "a"
	},
	{
		NAME : "b"
	},
	{
		NAME : "c"
	},
	{
		NAME : "d"
	},
	{
		NAME : "e"
	}
];
dump( arrayToStruct( arr ) );
// member function
dump( arr.toStruct() );

Last updated

Was this helpful?