Getting started with Structures in ColdFusion

Readability

Getting started with Structures in ColdFusion

The fol­low­ing exam­ples show how you can get started with using the var­i­ous struc­ture func­tions in ColdFusion.

Cre­at­ing a new structure/​object using ColdFusion

The fol­low­ing exam­ple shows how you can cre­ate a new struc­ture in Cold­Fu­sion using the structNew() func­tion or using the {} shortcut:



Deter­min­ing if a vari­able is a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can deter­mine if a vari­able is a struc­ture using the isStruct() method:



isStruct(structObj): #isStruct(structObj)#
isStruct(17): #isStruct(17)#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

isStruct(structObj): YES
isStruct(17): NO

Adding new name/​value pairs to a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can insert new name/​value pairs into a struc­ture in Cold­Fu­sion using dot nota­tion, array nota­tion, or using the structInsert() function:


    structObj = structNew();
    structObj.foo = "bar";
    structObj['nom'] = "blah blah blah";
    structInsert(structObj, "uuid", "abc123");

There is also a struc­ture short­hand nota­tion where you can cre­ate and pop­u­late a struc­ture in one sim­ple line of code:


If you are using the structInsert() func­tion, you can also pass an optional Boolean fourth argu­ment, allowOverwrite, which con­trols whether an error will be thrown if that key already exists in the struc­ture (false, default) or not (true). For exam­ple, the fol­low­ing code uses the structInsert() func­tion to insert the same key (“uuid”) twice. Since the allowOverwrite argu­ment is false, the sec­ond structInsert will throw an error, which we can catch in our try..catch block:




    
    
        #cfcatch.message#
#cfcatch.detail#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

Can­not insert item with key uuid.
This key already exists.

Or, you could use a <CFSCRIPT> instead of CFML, as seen in the fol­low­ing example:


    structObj = structNew();
    structInsert(structObj, "uuid", "abc123", false);
    try {
        structInsert(structObj, "uuid", "xyz789", false);
    }
    catch (any e) {
       writeOutput(e.message & "
" & e.detail); }

Updat­ing val­ues in a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can update a name/​value pair in a struc­ture in Cold­Fu­sion using dot nota­tion, array nota­tion, or using the structInsert() func­tion (and set­ting the Boolean allowOverwrite argu­ment to true), or using the structUpdate() function:


    structObj = structNew();
    structObj.foo = "bar";
    writeOutput("1) " & structObj.foo & "
"); structObj.foo = "dot notation"; writeOutput("2) " & structObj.foo & "
"); structInsert(structObj, "foo", "using structInsert()", true); writeOutput("3) " & structObj.foo & "
"); structUpdate(structObj, "foo", "using structUpdate()"); writeOutput("4) " & structObj.foo & "
");

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

1) bar
2) dot nota­tion
3) using structIn­sert()
4) using structUpdate()

Check­ing whether a struc­ture is empty using ColdFusion

The fol­low­ing exam­ple shows how you can deter­mine whether a struc­ture is empty by using the structIsEmpty() function:


1) #structIsEmpty(structObj)#
2) #structIsEmpty(structObj)#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

1) YES
2) NO

Check­ing whether a key exists in a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can check whether a key exists in a struc­ture in Cold­Fu­sion using the structKeyExists() function:





structKeyExists(structObj, "foo"): #structKeyExists(structObj, "foo")#
structKeyExists(structObj, "secretKey"): #structKeyExists(structObj, "secretKey")#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

structKeyExists(structObj, “foo”): YES
structKeyExists(structObj, “secretKey”): NO

Retriev­ing val­ues from a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can retrieve a value from a struc­ture in Cold­Fu­sion using dot nota­tion, array nota­tion, or using the structFind() function:


    structObj = structNew();
    structObj.foo = "bar";
    structObj['hyphenated-key'] = "oh my!";



dot notation: #structObj.foo#
array notation: #structObj["hyphenated-key"]#
structFind (simple): #structFind(structObj, "foo")#
structFind (hyphenated): #structFind(structObj, "hyphenated-key")#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

dot nota­tion: bar
array nota­tion: oh my!
structFind (sim­ple): bar
structFind (hyphen­ated): oh my!

Remov­ing val­ues from a struc­ture using ColdFusion

The fol­low­ing exam­ple shows how you can remove an ele­ment from a struc­ture in Cold­Fu­sion using the structDelete() function:


    structObj = structNew();
    structObj.foo = "bar";
    structObj.nom = "blah blah blah";
    structObj.uuid = "abc123";
    writeOutput("struct has " & structCount(structObj) & " keys: " & structKeyList(structObj) & "
"); structDelete(structObj, "uuid"); writeOutput("struct has " & structCount(structObj) & " keys: " & structKeyList(structObj) & "
");

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

struct has 3 keys: UUID,NOM,FOO
struct has 2 keys: NOM,FOO

The structDelete() func­tion also accepts an optional Boolean third argu­ment, indicateNotExisting, which lets you spec­ify what Boolean value the structDelete() func­tion returns if the key existed in the struc­ture or not.


    structObj = structNew();
    structObj.uuid = "abc123";
    keyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist");
    writeOutput("keyExisted? " & keyExisted & "
");

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

keyEx­isted? YES

So even though the key never existed in the struc­ture, the structDelete() func­tion returned YES. By pass­ing the Boolean third para­me­ter, indicateNotExisting, you can get Cold­Fu­sion to return “YES” only if the key exists or “NO” if the key wasn’t found (true), or you can return “YES” regard­less of whether the key existed prior to dele­tion (false, default):


    structObj = structNew();
    structObj.uuid = "abc123";
    keyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist", false);
    keyActuallyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist", true);
    writeOutput("keyExisted? " & keyExisted & "
"); writeOutput("keyActuallyExisted? " & keyActuallyExisted & "
");

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

keyEx­isted? YES
key­Ac­tu­al­lyEx­isted? NO

Merg­ing struc­tures using ColdFusion

The fol­low­ing exam­ple shows how you can merge/​append two struc­tures in Cold­Fu­sion using the structAppend() function:













structAppend() was successful: #result#

The structAppend() func­tion accepts a third optional Boolean attribute, overwriteFlag, which spec­i­fies whether val­ues in sec­ond struct over­write val­ues in the first struct (true, default), or whether val­ues in the sec­ond struct do not over­write val­ues in the first struct (false).

The fol­low­ing exam­ple shows how you can set the Boolean overwriteFlag attribute so that any exist­ing keys are not over­writ­ten if they already exist in the first structure:







Sort­ing struc­tures in ColdFusion

The fol­low­ing exam­ple shows how you can sort a structure’s keys in Cold­Fu­sion using the structSort() function:


    stuff = structNew();
    stuff.item1 = "Lauren";
    stuff.item2 = "Joan";
    stuff.item3 = "Peter";
    stuff.item4 = "Brian";
    stuff.item5 = "Jacob";
    stuff.item6 = "Ella";
    stuff.item7 = "Joann";


sorted struct keys = #arrayToList(structSort(stuff))#
#stuff[idx]#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

sorted struct = ITEM4,ITEM6,ITEM5,ITEM2,ITEM7,ITEM1,ITEM3
Brian
Ella
Jacob
Joan
Joann
Lau­ren
Peter

You can set the sort type (“text” (default), “textNo­Case”, or “numeric”) by spec­i­fy­ing the optional sec­ond attribute, sortType, as seen in the fol­low­ing example:


    stuff = structNew();
    stuff.item1 = "P., Lauren";
    stuff.item2 = "L., Joan";
    stuff.item3 = "d., Peter";
    stuff.item4 = "O., Brian";
    stuff.item5 = "G., Jacob";
    stuff.item6 = "M., Ella";
    stuff.item7 = "A., Joann";


sortType = "text"
#stuff[idx]#
sortType = "textNoCase"
#stuff[idx]#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

sort­Type = “text“
A., Joann
G., Jacob
L., Joan
M., Ella
O., Brian
P., Lau­ren
d., Peter

sort­Type = “textNo­Case“
A., Joann
d., Peter
G., Jacob
L., Joan
M., Ella
O., Brian
P., Lauren

Or you can do a numeric sort by set­ting the sortType attribute to “numeric”, as seen in the fol­low­ing example:


    stuff = structNew();
    stuff.item1 = 123456;
    stuff.item2 = 2354;
    stuff.item3 = 95;
    stuff.item4 = 3364;
    stuff.item5 = 87451;
    stuff.item6 = 655;
    stuff.item7 = 111;



    #stuff[idx]#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

95
111
655
2354
3364
87451
123456

You can set the sort order (“asc” (default), or “desc”) by spec­i­fy­ing the optional third attribute, sortOrder, as seen in the fol­low­ing example:


    stuff = structNew();
    stuff.item1 = "P., Lauren";
    stuff.item2 = "L., Joan";
    stuff.item3 = "d., Peter";
    stuff.item4 = "O., Brian";
    stuff.item5 = "G., Jacob";
    stuff.item6 = "M., Ella";
    stuff.item7 = "A., Joann";



    #stuff[idx]#

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

P., Lau­ren
O., Brian
M., Ella
L., Joan
G., Jacob
d., Peter
A., Joann

You can also sort com­plex, nested struc­tures by spec­i­fy­ing the optional fourth attribute, path­To­SubEle­ment, as seen in the fol­low­ing example:


    stuff = structNew();
    stuff.person1 = structNew();
    stuff.person1.id = 1;
    stuff.person1.firstName = "Xander";
    stuff.person1.lastName = "Crews";
    
    stuff.person2 = structNew();
    stuff.person2.id = 2;
    stuff.person2.firstName = "Wendell";
    stuff.person2.lastName = "Stamps";
    
    stuff.person3 = structNew();
    stuff.person3.id = 3;
    stuff.person3.firstName = "Grace";
    stuff.person3.lastName = "Ryan";
    
    stuff.person4 = structNew();
    stuff.person4.id = 4;
    stuff.person4.firstName = "Arthur";
    stuff.person4.lastName = "Watley";



    #stuff[idx].lastName#, #stuff[idx].firstName# (#stuff[idx].id#)

The pre­vi­ous exam­ple out­puts the fol­low­ing text:

Crews, Xan­der (1)
Ryan, Grace (3)
Stamps, Wen­dell (2)
Wat­ley, Arthur (4)

The following examples show how you can get started with using the various structure functions in ColdFusion.

Creating a new structure/object using ColdFusion

The following example shows how you can create a new structure in ColdFusion using the structNew() function or using the {} shortcut:

<cfset structObj1 = structNew() />
<cfset structObj2 = {} />

Determining if a variable is a structure using ColdFusion

The following example shows how you can determine if a variable is a structure using the isStruct() method:

<cfset structObj = structNew() />
<cfoutput>
isStruct(structObj): #isStruct(structObj)#<br/>
isStruct(17): #isStruct(17)#<br/>
</cfoutput>

The previous example outputs the following text:

isStruct(structObj): YES
isStruct(17): NO

Adding new name/value pairs to a structure using ColdFusion

The following example shows how you can insert new name/value pairs into a structure in ColdFusion using dot notation, array notation, or using the structInsert() function:

<cfscript>
    structObj = structNew();
    structObj.foo = "bar";
    structObj['nom'] = "blah blah blah";
    structInsert(structObj, "uuid", "abc123");
</cfscript>

There is also a structure shorthand notation where you can create and populate a structure in one simple line of code:

<cfset structObj = {foo="bar", nom="blah blah blah", uuid="abc123"} />

If you are using the structInsert() function, you can also pass an optional Boolean fourth argument, allowOverwrite, which controls whether an error will be thrown if that key already exists in the structure (false, default) or not (true). For example, the following code uses the structInsert() function to insert the same key (“uuid”) twice. Since the allowOverwrite argument is false, the second structInsert will throw an error, which we can catch in our try..catch block:

<cfset structObj = structNew() />
<cfset structInsert(structObj, "uuid", "abc123", false) />
<cftry>
    <cfset structInsert(structObj, "uuid", "xyz789", false) />
    <cfcatch type="any">
        <cfoutput>#cfcatch.message#<br/>#cfcatch.detail#</cfoutput>
    </cfcatch>
</cftry>

The previous example outputs the following text:

Cannot insert item with key uuid.
This key already exists.

Or, you could use a <CFSCRIPT> instead of CFML, as seen in the following example:

<cfscript>
    structObj = structNew();
    structInsert(structObj, "uuid", "abc123", false);
    try {
        structInsert(structObj, "uuid", "xyz789", false);
    }
    catch (any e) {
       writeOutput(e.message & "<br/>" & e.detail);
    }
</cfscript>

Updating values in a structure using ColdFusion

The following example shows how you can update a name/value pair in a structure in ColdFusion using dot notation, array notation, or using the structInsert() function (and setting the Boolean allowOverwrite argument to true), or using the structUpdate() function:

<cfscript>
    structObj = structNew();
    structObj.foo = "bar";
    writeOutput("1) " & structObj.foo & "<br/>");
    structObj.foo = "dot notation";
    writeOutput("2) " & structObj.foo & "<br/>");
    structInsert(structObj, "foo", "using structInsert()", true);
    writeOutput("3) " & structObj.foo & "<br/>");
    structUpdate(structObj, "foo", "using structUpdate()");
    writeOutput("4) " & structObj.foo & "<br/>");
</cfscript>

The previous example outputs the following text:

1) bar
2) dot notation
3) using structInsert()
4) using structUpdate()

Checking whether a structure is empty using ColdFusion

The following example shows how you can determine whether a structure is empty by using the structIsEmpty() function:

<cfset structObj = structNew() />
<cfoutput>1) #structIsEmpty(structObj)#<br/></cfoutput>
 
<cfset structObj.foo = "bar" />
<cfoutput>2) #structIsEmpty(structObj)#<br/></cfoutput>

The previous example outputs the following text:

1) YES
2) NO

Checking whether a key exists in a structure using ColdFusion

The following example shows how you can check whether a key exists in a structure in ColdFusion using the structKeyExists() function:

<cfset structObj = structNew() />
<cfset structObj.foo = "bar" />
 
<cfoutput>
structKeyExists(structObj, "foo"): #structKeyExists(structObj, "foo")#<br/>
structKeyExists(structObj, "secretKey"): #structKeyExists(structObj, "secretKey")#<br/>
</cfoutput>

The previous example outputs the following text:

structKeyExists(structObj, “foo”): YES
structKeyExists(structObj, “secretKey”): NO

Retrieving values from a structure using ColdFusion

The following example shows how you can retrieve a value from a structure in ColdFusion using dot notation, array notation, or using the structFind() function:

<cfscript>
    structObj = structNew();
    structObj.foo = "bar";
    structObj['hyphenated-key'] = "oh my!";
</cfscript>
 
<cfoutput>
<table>
    <tr>
        <td>dot notation:</td>
        <td>#structObj.foo#</td>
    </tr>
    <tr>
        <td>array notation:</td>
        <td>#structObj["hyphenated-key"]#</td>
    </tr>
    <tr>
        <td>structFind (simple):</td>
        <td>#structFind(structObj, "foo")#</td>
    </tr>
    <tr>
        <td>structFind (hyphenated):</td>
        <td>#structFind(structObj, "hyphenated-key")#</td>
    </tr>
</table>
</cfoutput>

The previous example outputs the following text:

dot notation: bar
array notation: oh my!
structFind (simple): bar
structFind (hyphenated): oh my!

Removing values from a structure using ColdFusion

The following example shows how you can remove an element from a structure in ColdFusion using the structDelete() function:

<cfscript>
    structObj = structNew();
    structObj.foo = "bar";
    structObj.nom = "blah blah blah";
    structObj.uuid = "abc123";
    writeOutput("struct has " & structCount(structObj) & " keys: " & structKeyList(structObj) & "<br/>");
 
    structDelete(structObj, "uuid");
    writeOutput("struct has " & structCount(structObj) & " keys: " & structKeyList(structObj) & "<br/>");
</cfscript>

The previous example outputs the following text:

struct has 3 keys: UUID,NOM,FOO
struct has 2 keys: NOM,FOO

The structDelete() function also accepts an optional Boolean third argument, indicateNotExisting, which lets you specify what Boolean value the structDelete() function returns if the key existed in the structure or not.

<cfscript>
    structObj = structNew();
    structObj.uuid = "abc123";
    keyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist");
    writeOutput("keyExisted? " & keyExisted & "<br/>");
</cfscript>

The previous example outputs the following text:

keyExisted? YES

So even though the key never existed in the structure, the structDelete() function returned YES. By passing the Boolean third parameter, indicateNotExisting, you can get ColdFusion to return “YES” only if the key exists or “NO” if the key wasn’t found (true), or you can return “YES” regardless of whether the key existed prior to deletion (false, default):

<cfscript>
    structObj = structNew();
    structObj.uuid = "abc123";
    keyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist", false);
    keyActuallyExisted = structDelete(structObj, "someKeyThatCertainlyDoesntExist", true);
    writeOutput("keyExisted? " & keyExisted & "<br/>");
    writeOutput("keyActuallyExisted? " & keyActuallyExisted & "<br/>");
</cfscript>

The previous example outputs the following text:

keyExisted? YES
keyActuallyExisted? NO

Merging structures using ColdFusion

The following example shows how you can merge/append two structures in ColdFusion using the structAppend() function:

<cfset structObj1 = structNew() />
<cfset structObj1.key1 = "struct1, key1" />
<cfset structObj1.key2 = "struct1, key2" />
<cfdump var="#structObj1#" label="structObj1" />
 
<cfset structObj2 = structNew() />
<cfset structObj2.key1 = "struct2, key1" />
<cfset structObj2.key3 = "struct2, key3" />
<cfdump var="#structObj2#" label="structObj2" />
 
<cfset result = structAppend(structObj1, structObj2) />
<cfdump var="#structObj1#" label="structObj1" />
<cfoutput>structAppend() was successful: #result#<br/></cfoutput>

The structAppend() function accepts a third optional Boolean attribute, overwriteFlag, which specifies whether values in second struct overwrite values in the first struct (true, default), or whether values in the second struct do not overwrite values in the first struct (false).

The following example shows how you can set the Boolean overwriteFlag attribute so that any existing keys are not overwritten if they already exist in the first structure:

<cfset structObj1 = structNew() />
<cfset structObj1.key1 = "struct1, key1" />
<cfset structObj1.key2 = "struct1, key2" />
<cfdump var="#structObj1#" label="structObj1" />
<br />
<cfset structObj2 = structNew() />
<cfset structObj2.key1 = "struct2, key1" />
<cfset structObj2.key3 = "struct2, key3" />
<cfdump var="#structObj2#" label="structObj2" />
<br/>
<cfset result = structAppend(structObj1, structObj2) />
<cfdump var="#structObj1#" label="structObj1" />
 
<cfset structObj3 = structNew() />
<cfset structObj3.key1 = "struct3, key1" />
<cfset structObj3.key2 = "struct3, key2" />
<cfset structObj3.key3 = "struct3, key3" />
<cfset structObj3.key4 = "struct3, key4" />
<cfset structAppend(structObj1, structObj3, false) />
<cfdump var="#structObj1#" />

Sorting structures in ColdFusion

The following example shows how you can sort a structure’s keys in ColdFusion using the structSort() function:

<cfscript>
    stuff = structNew();
    stuff.item1 = "Lauren";
    stuff.item2 = "Joan";
    stuff.item3 = "Peter";
    stuff.item4 = "Brian";
    stuff.item5 = "Jacob";
    stuff.item6 = "Ella";
    stuff.item7 = "Joann";
</cfscript>
 
<cfoutput>sorted struct keys = #arrayToList(structSort(stuff))#<br/></cfoutput>
<cfloop array="#structSort(stuff)#" index="idx">
    <cfoutput>#stuff[idx]#<br/></cfoutput>
</cfloop>

The previous example outputs the following text:

sorted struct = ITEM4,ITEM6,ITEM5,ITEM2,ITEM7,ITEM1,ITEM3
Brian
Ella
Jacob
Joan
Joann
Lauren
Peter

You can set the sort type (“text” (default), “textNoCase”, or “numeric”) by specifying the optional second attribute, sortType, as seen in the following example:

<cfscript>
    stuff = structNew();
    stuff.item1 = "P., Lauren";
    stuff.item2 = "L., Joan";
    stuff.item3 = "d., Peter";
    stuff.item4 = "O., Brian";
    stuff.item5 = "G., Jacob";
    stuff.item6 = "M., Ella";
    stuff.item7 = "A., Joann";
</cfscript>
 
sortType = "text"<br/>
<cfloop array="#structSort(stuff, 'text')#" index="idx">
    <cfoutput>#stuff[idx]#<br/></cfoutput>
</cfloop>
 
sortType = "textNoCase"<br/>
<cfloop array="#structSort(stuff, 'textNoCase')#" index="idx">
    <cfoutput>#stuff[idx]#<br/></cfoutput>
</cfloop>

The previous example outputs the following text:

sortType = “text”
A., Joann
G., Jacob
L., Joan
M., Ella
O., Brian
P., Lauren
d., Peter

sortType = “textNoCase”
A., Joann
d., Peter
G., Jacob
L., Joan
M., Ella
O., Brian
P., Lauren

Or you can do a numeric sort by setting the sortType attribute to “numeric”, as seen in the following example:

<cfscript>
    stuff = structNew();
    stuff.item1 = 123456;
    stuff.item2 = 2354;
    stuff.item3 = 95;
    stuff.item4 = 3364;
    stuff.item5 = 87451;
    stuff.item6 = 655;
    stuff.item7 = 111;
</cfscript>
 
<cfloop array="#structSort(stuff, 'numeric')#" index="idx">
    <cfoutput>#stuff[idx]#<br/></cfoutput>
</cfloop>

The previous example outputs the following text:

95
111
655
2354
3364
87451
123456

You can set the sort order (“asc” (default), or “desc”) by specifying the optional third attribute, sortOrder, as seen in the following example:

<cfscript>
    stuff = structNew();
    stuff.item1 = "P., Lauren";
    stuff.item2 = "L., Joan";
    stuff.item3 = "d., Peter";
    stuff.item4 = "O., Brian";
    stuff.item5 = "G., Jacob";
    stuff.item6 = "M., Ella";
    stuff.item7 = "A., Joann";
</cfscript>
 
<cfloop array="#structSort(stuff, 'textNoCase', 'desc')#" index="idx">
    <cfoutput>#stuff[idx]#<br/></cfoutput>
</cfloop>

The previous example outputs the following text:

P., Lauren
O., Brian
M., Ella
L., Joan
G., Jacob
d., Peter
A., Joann

You can also sort complex, nested structures by specifying the optional fourth attribute, pathToSubElement, as seen in the following example:

<cfscript>
    stuff = structNew();
    stuff.person1 = structNew();
    stuff.person1.id = 1;
    stuff.person1.firstName = "Xander";
    stuff.person1.lastName = "Crews";
 
    stuff.person2 = structNew();
    stuff.person2.id = 2;
    stuff.person2.firstName = "Wendell";
    stuff.person2.lastName = "Stamps";
 
    stuff.person3 = structNew();
    stuff.person3.id = 3;
    stuff.person3.firstName = "Grace";
    stuff.person3.lastName = "Ryan";
 
    stuff.person4 = structNew();
    stuff.person4.id = 4;
    stuff.person4.firstName = "Arthur";
    stuff.person4.lastName = "Watley";
</cfscript>
 
<cfloop array="#structSort(stuff, 'text', 'asc', 'lastName')#" index="idx">
    <cfoutput>#stuff[idx].lastName#, #stuff[idx].firstName# (#stuff[idx].id#)<br/></cfoutput>
</cfloop>

The previous example outputs the following text:

Crews, Xander (1)
Ryan, Grace (3)
Stamps, Wendell (2)
Watley, Arthur (4)

Leave a Reply

Your email address will not be published.