0

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.

1
  • Better in what way? Is the array really an arbitrary structure? Why not give an example of what it looks like? What is the source of the data? Commented Aug 26, 2013 at 12:40

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

10 points for the use of the word "paucity" in a sentence. nicely done :)
I'd agree with the 10 pts for using "paucity". But I think Adam should get another 10 for showing the marks of a true developer. He saw a problem, thought "There should be a UDF for this", looked it up and found a UDF that he, himself, wrote. THIS is why I always love reading Adam. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.