ArrayToStruct()

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

ArrayToStruct( array=array, valueAsKey=boolean );

Returns: Struct

Argument Description Default
array
array, required

array to translate

valueAsKey
boolean, optional

use the value as the key of the struct, rather than the index

Introduced: 6.0.0.79

false

Examples

Simple Array

arr = ['a','b','c','d','e','f','g'];
dump(arrayToStruct(arr));
if (listFirst(server.lucee.version,".") gte 6)
    dump(arrayToStruct(arr, true));

//member function dump(arr.toStruct());

Array of Structs

arr = [
    {name:'a'},
    {name:'b'},
    {name:'c'},
    {name:'d'},
    {name:'e'}
];
dump(arrayToStruct(arr));

//member function dump(arr.toStruct());

See also