i am trying to filter the list from the array of s...
# cfml-beginners
g
i am trying to filter the list from the array of structs to display only values needed, what went wrong here https://trycf.com/gist/50f3aeab1dabcdc78b722f3d02dd154a/acf?theme=monokai
c
arrayFilter is your friend here
a
also, you are missing a closing a
)
in your IF. You have:
Copy code
if(listfindnocase(lstremovekeys,key.address_state) {
SHOULD BE
Copy code
if(listfindnocase(lstremovekeys,key.address_state)) {
making this change outputs:
Copy code
Address State = DC
Address State = NY
c
Something like:
Copy code
data = [
     { address_city : "Washington" , address_state : "DC" } ,
     { address_city : "New York" , address_state : "NY" } ,
     { address_city : "Miami" , address_state : "FL" }
] ;

lstremovekeys = 'NY';

newData = arrayFilter( data, function( item, index ){
    return listFindNoCase( lstremovekeys, item.address_state ) ? false : true;
} );

writeDump(newData);
a
@gsr excellent work giving us some code this time. But make sure to run it before showing it to us 😉 That code doesn't compile, as @Adam Palcich said. And instead of "what went wrong here", tell us exactly what yer expecting to see, and what yer seeing instead. "it's still got washington, but it should have been removed" or something.
This is a good improvement from yer earlier questions though