Question

I have an array of structs in my script, and I need to check inside the entire array of structs if somewhere inside a struct, the "id" key has a specific value.

I could do this with a loop, but is there any better/faster way to do this? Note that it needs to be compatible with ColdFusion 8, so ArrayFind is not available.

Was it helpful?

Solution

As Peter suggests, it's hard to say definitely given the paucity of info provided, but if the key value is likely to be unique in the data structure, the you could use structFindValue() to locate it. The challenge here is that it does not pay attention to the KEY that the value is in. I do not know what Adobe / Macromedia were thinking in providing structFindKey() and structFindValue(), but no structFindKeyValue().

On a whim I checked CFLib to see if there was a UDF to cover that ground. Not only is there one, it seems I wrote it (my memory is like a sieve sometimes): structFindKeyWithValue(). That's written for CF9, but it shouldn't take too much to back-port it to CF8.

This is a bit of a general answer. If you provide better info, we can give a better answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top