I was talking with another fellow programmer at work and we use ColdFusion. He is telling me simply look for a value in an array I have to do a whole loop? Is it true there is no function in ColdFusion 8 to simply look for a value in an Array?
arrayFind()
doesn't exist in ColdFusion 8. However, you don't need to loop. There are two ways:
Take advantage of the fact that ColdFusion arrays implement the interface java.util.List:
<cfset valueToFind = 1>
<cfset array = [1,2,3]>
<!--- add one because CF does 1 based vs. Java 0 based arrays --->
<cfset position = array.indexOf(valueToFind) + 1>
Use list operations:
<cfset valueToFind = 1>
<cfset array = [1,2,3]>
<cfset position = listFind(arrayToList(array), valueToFind)>
The first (Java List) method is faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With