Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
I love working with arrays. They are fast, sleek and always maintain their sort order unlike structures. But they are not always easy to deal with. Finding data in an array always meant looping through and doing comparisons and then breaking out of the loop when you found what you want. And it's never been easy to just delete an entry and move on without first going through the same looping business above, to figure out which node you want to delete. Well, ColdFusion 9 comes to the rescue with four new array functions. ArrayContains, Delete, Find, and FindNoCase.
So, in Chapter9 open up the arrays.cfm file. Now, in here I have three person structures and I have put each of those particular people into an array called MyArray. So let's just go ahead and dump this out and see what it looks like. So, here you can see a node of mine. I have Dan Short, node 2 I have Kirk Werner, and node 3 I have Ben Forta. That's easy enough, but what's always been difficult before is how do I figure out which node Kirk Werner might be in, if I've created this list dynamically.
In ColdFusion 9, I can simply say ArrayFind and I specify the array that I want to search in, and then I tell it the object that I want it to look for. Now, I could just tell the string I wan it to look for. But in this case I am actually going to say look for this complex object inside of the MyArray array. So I'll go and check that file out here. And it tells me that Kirk Werner is in position number 2. If I go back to my source and say let's look for Person3, and then check out the file.
It tells me that Ben Forta is in position number 3. So again, it's gone through the array and looked to find a complex object in a specific node in the array. If I wanted to look for a cfc that had unique properties and methods on it, it would work exactly the same. Now, the rest of the functions work the same. So, if I go over to my source code I can do ArrayContains. It will tell me yes or no whether or not Person3 actually exist in this array. I go over here and preview, and sure enough Ben Forta is inside of my array.
Now, the other thing I can do is easily delete a person. I can do ArrayDelete and then I'll dump out my array again, and now Ben Forta has been removed from the array. It's the little things like this that really make developing with ColdFusion fun. While the addition of these four little functions doesn't really seem like much, these will really have an impact on how you develop your applications.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105366 Viewers
56 Video lessons · 117088 Viewers
71 Video lessons · 86306 Viewers
131 Video lessons · 41247 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.