Utility Function: ArrayFind()

I sometimes need to search an array of strings for a specific value, so I came up with this function.

<cffunction name="ArrayFind" access="public" output="false" returntype="numeric">
    <cfargument name="array" type="array" required="true" />
    <cfargument name="find" type="any" required="true" />
    
    <cfset var position = 0 />
    <cfset var x = 0 />
    
    <cfloop from="1" to="#ArrayLen(arguments.array)#" index="x">
        <cfif arguments.array[x] eq arguments.find>
            <cfset position = x />
            <cfbreak />
        </cfif>
    </cfloop>
    
    <cfreturn position />
</cffunction>

 

Related Blog Entries

Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.