?
Solved

How do you delete a structure from an array?

Posted on 2009-07-07
4
Medium Priority
?
321 Views
Last Modified: 2012-05-07
I have an array that contains structures, and I want to delete one based on a URL variable. Let's say my array looks like the following:

ThisIsMy - Array
1. ThisIsMy - Structure: firstname, Bob; lastname: Jones; age: 30
2. ThisIsMy - Structure: firstname, Jane; lastname: Doe; age: 23
3. ThisIsMy - Structure: firstname, Sally; lastname: Smith; age: 28

I realize this has to be CF 101 stuff, but how in the world can I delete, say, the second structure in the array if I have delete=2 as a URL variable? All the code I've tried has resulted in a "complex object types cannot be converted to simple values" error or the dreaded "object of type class java.lang.Boolean cannot be used as an array."
0
Comment
Question by:SiobhanElara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24799347
ArrayDeleteAt() ...

So if this is your array before-hand :

ThisIsMy[1].Firstname = Bob
ThisIsMy[1].LastName = Jones
ThisIsMy[1].Age = 30
ThisIsMy[2].Firstname = Jane
ThisIsMy[2].LastName = Doe
ThisIsMy[2].Age = 23
ThisIsMy[3].Firstname = Sally
ThisIsMy[3].LastName = Smith
ThisIsMy[3].Age = 28

... and you do <cfset ArrayDeleteAt(2)>
Then this is your result :

ThisIsMy[1].Firstname = Bob
ThisIsMy[1].LastName = Jones
ThisIsMy[1].Age = 30
ThisIsMy[2].Firstname = Sally
ThisIsMy[2].LastName = Smith
ThisIsMy[2].Age = 28
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 24799360
It doesn't sound like you want to delete the structure of the array, it sounds like you want to delete the array element itself.

If your example, if you pass in delete=2, then you want to delete Jane Doe age 23, the entire element of the array.

To do that, use :   <cfset tmp =  arrayDeleteAt(thisIsMy,2)>

where thisIsMy is the array as you have indicated.

0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24799367
Whoops, i forgot to put the array name in there.

gdemaria is correct!
0
 
LVL 18

Expert Comment

by:Plucka
ID: 24799637
Just incase you want to remove the structure and not delete the array element, you can just do this

<cfset ThisIsMy = [] />

<cfset s1 = {firstName = 'Fred', lastName = 'Flintstone'} />
<cfset s2 = {firstName = 'Fred', lastName = 'Flintstone'} />
<cfset s3 = {firstName = 'Fred', lastName = 'Flintstone'} />

<cfset arrayAppend(ThisIsMy, s1) />
<cfset arrayAppend(ThisIsMy, s2) />
<cfset arrayAppend(ThisIsMy, s3) />

<cfset ThisIsMy[2] = "" />

<cfdump var="#ThisIsMy#" />
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question