Userid inference when structure is stored in an array

I have the following array with structure inside each array (see jsfiddle for how the array looks like).

How do I iterate over the array and then get the structure inside the array to pull out the user id? I keep getting errors with the options I've tried. The most common error I get is:

Must be a valid structure or COM object


Here is the code I have to loop over the array and structure that generates the error above (see the jsfiddle for what the array looks like).

<cfloop from="1" to="#ArrayLen(getTeamDetails)#" index="s">
    #s#) #getTeamDetails[s][uid]#<br>   


Mark asked for some more code, so I included how I populate an array / structure:

<cfoutput query="getTeam">
    <cfset getTeamDetails[getTeam.currentrow] = StructNew()>
    <cfset a = StructInsert(getTeamDetails[getTeam.currentrow], "firstname", getTeam.firstname, 1)>
    <cfset a = StructInsert(getTeamDetails[getTeam.currentrow], "lastname", getTeam.lastname, 1)>
    <cfset a = StructInsert(getTeamDetails[getTeam.currentrow], "uid", getTeam.uid, 1)>



source to share

1 answer

I think this should work:

<cfloop from="1" to="#ArrayLen(getTeamDetails)#" index="s">
    #s#) #getTeamDetails[s].uid#<br>   


I created my array and structure from scratch and looped through it to access the structure you need to access.

ThisArray = arrayNew(1);
for (i = 1; i lte 3; i=i+1) {
    ThisStruct = structNew();
    ThisStruct.UID = "123";
    arrayAppend(ThisArray, ThisStruct);
for (i = 1; i lte arrayLen(ThisArray); i=i+1) {
    ThisOutput = "#i#) #ThisArray[i].UID# <br>";
<cfdump var="#ThisArray#">




All Articles