Search code examples
arrayscoldfusioncfmllucee

trying to get the value of the struct inside an array


Looking for a one liner code either in java or cfm, where i do not need to loop over te array of structs to use te structfind to get the value from it.

right now looking at it,

Coldfusion - How to loop through an Array of Structure and print out dynamically all KEY values?

where i can loop over and get the value of the key match

but trying to check if something like this can be done

<cfset myvalue = structfindvaluefromAnything(myarrayofstruct,"infor")>

Solution

  • I like Sev's approach. I would change it slightly

    <cfscript>
         superheroes=[
               {"name":"Iron Man","member":"Avengers"},
               {"name":"Spider-Man","member":"Avengers"},
               {"name":"Wonder Woman","member":"Justice League"},
               {"name":"Hulk","member":"Avengers"},
               {"name":"Thor","member":"Avengers"},
               {"name":"Aquaman","member":"Justice League"}
         ];
     
         avengers = superheroes.filter(function(item) { 
            return item.member ==  "Avengers";
        });
         writeDump(avengers);
    </cfscript>