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 />
    <cfreturn position />


Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

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.

Post a job. Find one. authenticjobs.com

Interested in becoming a sponsor? Contact me.