Oh, I forgot to say... so, I mention that fact that you can't use
arrayToList unless you are sure there are no commas in the data. (Or, if
you sure there is no X, where X is a custom delimiter.) If you can't be
sure of that, you must walk through the array. I wrote a UDF that will
do this.


/**
 * ArrayFind will search an array for a value. We don't use a simple
 * convert to list/listfind method because we don't want to worry about
delimiters
 *
 * @param arr           The array to search
 * @param target        The string to search for
 * @return                      Returns the position match, or 0
 */
function ArrayFind(arr,target) {
        var i = 1;
        for(i = 1; i lte arrayLen(arr); i = i+1) {
                if(arr[i] eq target) return i;
        }
        return 0;
}

We also have a UDF at cflib.org that will search a sorted array:
http://www.cflib.org/udf.cfm?ID=150

=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Macromedia

Email    : [EMAIL PROTECTED]
Yahoo IM : morpheus

"My ally is the Force, and a powerful ally it is." - Yoda 

> -----Original Message-----
> From: Raymond Camden [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 20, 2001 8:49 AM
> To: CF-Talk
> Subject: RE: Finding an a specific item in array
> 
> 
> Well, unfortunately, it looks like your array isn't an array of simple
> values, but an array of structures. If your array was all 
> simple values,
> and you were 100% sure that the values would not contain a common
> delimiter, then you could simply do:
> 
> <cfif not listFind(arrayToList(thearray),newID)>
> 
> This simply converts the array to a list, and then does a find on it.
> Since your array contains structs, you will have to loop through it.
> 
> <cfset haveIt = false>
> <cflock scope="session" type="readOnly" timeout=3>
> <cfloop index="x" from=1 to="#arrayLen(session.cart)#">
>       <cfif session.cart[x].item_id is newid>
>               <cfset haveIt = true>
>               <cfbreak>
>       </cfif>
> </cfloop>
> </cflock>
> 
> This will loop over the array and check the item_id value of each item
> in the array. If it finds it, it sets a boolean to true and 
> breaks out.
> If you want to remember x, you can also do a <cfset foundItAt = x>, or
> some such.
> 
______________________________________________________________________
Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to