Arrays

ColdFusion arrays are objects that can store a whole bunch of variables. As I said, arrays are objects; therefore, you can even create properties for them. We won’t get into creating their additional properties simply because we won’t create their properties very often. The length of the array does not have to be specified when you are declaring the variable. You can just keep adding variables or elements to it. This makes them perfect for situations where you need to capture an idea, but don’t have to keep creating variable names and polluting the global namespace with worthless variables.

Adding Elements to an Array

Example

If you have ever used an array, you will realize that they are really standard in ColdFusion. If you haven’t, then keep reading this paragraph. Our array’s name is myArray, which we create the array by using the <cfset myArray = arrayNew(1)>. You might be wondering what the 1 is for. All arrays in ColdFusion start with the index of one, which we specify here. Next, you see myArray[] with a number in those brackets. Those numbers are the order of elements in the array. So when we print our array using the <cfoutput> tags, we see that #myArray[1]# gives us “Pickles”. If you look, you can see that we already set that above in a <cfset> tag.

Array Functions

Adobe has all of the documentation for ColdFusion on their website if you ever need to reference it. ColdFusion Functions For an array, I have broken down the important array functions for you below.

ArrayAppend ArrayIsDefined ArrayNew ArraySum
ArrayAvg ArrayIsEmpty ArrayPrepend ArraySwap
ArrayClear ArrayLen ArrayResize ArrayToList
ArrayDeleteAt ArrayMax ArraySet IsArray
ArrayInsertAt ArrayMin ArraySort ListToArray
If you enjoyed this resource, support me by sharing this page with others.
Share on Facebook
Facebook
Share on Google+
Google+
Share on StumbleUpon
StumbleUpon
Digg this
Digg
Tweet about this on Twitter
Twitter
Share on Reddit
Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.