Quick thoughts on structs

June 6, 2019
Been a ColdFusion Developer since 1996
Wizard 22 posts
Followers: 12 people
Web Developer
2

Quick thoughts on structs

Been a ColdFusion Developer since 1996
Wizard 22 posts
Followers: 12 people
June 6, 2019

Here is a quick guide to all the different kinds of structs in ColdFusion

<cfscript>

// plain old struct
a = {};

a.b = “Bunny”;
a.c = “Canary”;
a.d = “Doggy”;
a.append({“a” : “Apple”});
a.append({“f” : “Frog”});

writedump(a);

// ordered
a = [:];

a.b = “Bunny”;
a.c = “Canary”;
a.d = “Doggy”;
a.append({“a” : “Apple”});
a.append({“f” : “Frog”});

writedump(a);

// sorted
a = StructNew(“ordered”, “text”);

a.b = “Bunny”;
a.c = “Canary”;
a.d = “Doggy”;
a.append({“a” : “Apple”});
a.append({“f” : “Frog”});

writedump(a);
</cfscript>

Which results in

See:

https://cffiddle.org/app/file?filepath=8bcbbb23-90ec-44a4-9893-b835ac7fbb97/3550b62f-5bbc-4efd-ad7b-4975d25155dc/c344182b-f312-4092-8621-e14d697887a2.cfm

Comments (2)
2019-06-07 23:32:28
2019-06-07 23:32:28

Attachment

I get different result from the cffiddle.

what’s the difference between 

a = [:] ;

and

a = StructNew(“ordered”, “text”); 

can’t find documentation for how to use [:] in ColdFusion

 

 

Like
2019-06-07 04:14:43
2019-06-07 04:14:43

Nice and handy!

Like
(1)
Add your comment