Creates a new, empty structure. The shorthand syntax for an empty unordered struct is {}
. You can also use the syntax {"key":"value"}
to initialize it with values. The shorthand syntax for an ordered struct is [:]
or [=]
. The shorthand for a case-sensitive struct is ${}
.The shorthand for a ordered and casesensitive struct is $[=]
.
NOTE: To preserve the case of the struct key, place quotes around it, otherwise it will be converted to uppercase.
structNew([type[[,sortType][,sortOrder][,localeSensitive]|[,callback]]])
→ returns struct
ordered
the order in which elements are added to the structure will be maintained. In Lucee linked
can be used in place of ordered
. casesensitive
the keys will remain case-sensitive. Additionally, ordered-casesensitive
can be used to create an ordered case-sensitive struct.
ordered
casesensitive
ordered-casesensitive
text
numeric
asc
asc
desc
false
Creates an unordered struct.
unordered = { a=1, c=3, b=2 };
writeDump( unordered );
Creates an unordered struct.
unordered = structNew();
unordered.a = 1;
unordered.b = 2;
unordered.c = 3;
writeDump( unordered );
CF 2016+ Creates an ordered struct. Note the square brackets.
ordered = [ a=1, b=2, c=3 ];
writeDump( ordered );
CF 2016+ Lucee 4.5+ Creates an ordered struct.
ordered = structNew( "ordered" );
ordered.a = 1;
ordered.b = 2;
ordered.c = 3;
writeDump( ordered );
CF 2016+ Lucee 5+ Creates an ordered struct.
ordered = [:];
ordered.a = 1;
ordered.b = 2;
ordered.c = 3;
writeDump( ordered );
CF 2021+ Creates a case-sensitive struct.
casesensitive = structNew( "casesensitive" );
casesensitive.a = 1;
casesensitive.B = 2;
casesensitive.c = 3;
writeDump( casesensitive );
CF 2021+ Creates a case-sensitive struct.
casesensitive = ${a=1, B=2, c=3};
writeDump( casesensitive );
CF 2021+ Creates a case-sensitive struct.
someStruct = structNew( "ordered-casesensitive" );
someStruct.c = 3;
someStruct.B = 2;
someStruct.a = 1;
writeDump( someStruct );
CF 2021+ Creates an ordered and case-sensitive struct.
someStruct = $[c=3, B=2, a=1];
writeDump( someStruct );
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.