StructNew()
Creates an empty structure.
The shorthand syntax for structNew is {};
The shorthand syntax to create an ordered structure is [:];
or [=];
You can also create structures with data using this syntax:
- a normal structure
{ "key": value };
- a linked/ordered structure use
[ "key": value ];
To preserve the case of the struct key, use a quoted value for the key, otherwise, it will be converted to uppercase.
StructNew( type=string, onMissingKey=function );
Returns: Struct
Examples
Lucee Script
dump(var=structNew("soft"), label="soft");
dump(var=structNew("weak"), label="weak");
dump(var=structNew("linked"), label="linked");
st = {
"one": [1,2,3],
"two": {
"three": QueryNew("id")
},
three: "unquoted keys don't preserve case"
};
dump( st );
dump( structKeyList(st) );
dump( structKeyExists(st, "one") );
// shorthand syntax for a new empty ordered struct, [=] also works
st = [:];
st.c = 1;
st.b = 2;
st.a = 3;
dump(st);
// shorthand syntax for an ordered struct with values
st = [
c: 1,
b: 2,
a: 3
];
dump(st);
Lucee Tags
<cfset st = structNew()>
<cfset st["name"] = "John Doe">
<cfset st["age"] = 30>
<cfset st["city"] = "New York">
<cfdump var="#st#">
See also
- Collections
- Structures
- ArrayNew()
- Struct
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)