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.

=======================================================================
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: Owens, Howard [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, December 19, 2001 7:59 PM
> To: CF-Talk
> Subject: Finding an a specific item in array
> 
> 
> Here's what I need to do -- and am not quite sure where to beginning.
> 
> I have an array of several items.  I might pullout a single 
> item in that
> array with something like this inside of a loop:
> 
> #session.cart[ThisOrder].ITEM_ID#
> 
> This might wind up being : Item ID: 567
> 
> That's fine.
> 
> But if the user accidently reselects that very same item, I 
> might want up
> with:
> 
> Item ID: 567
> Item ID: 567
> 
> I don't want that. I want to delete that second duplicate 
> item in the array
> and then resize the array.
> 
> But how do I find duplicates?
> 
> Or better yet, what I want to do is say:
> 
> "If this item already exists in the array, do not add this 
> new item into the
> array"
> 
> So I have to be able to quickly search through the entire 
> array and find the
> duplicate. But there doesn't seem to be an ArrayFind() 
> function.  So how
> would you approach this problem?
> 
> H.
> 
> 
> 
> Howard Owens
> Internet Operations Coordinator
> www.insidevc.com
> [EMAIL PROTECTED]
> AIM: GoCatGo1956
> 
> 
> 
______________________________________________________________________
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/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to