Tuesday, December 1, 2009

listAppend()...Why?

I ran into an annoyance twice this week with the listAppend() in Coldfusion. Below is two ways of storing stuff, an array and a list.



<cfset borders = arrayNew(1)/>

<cfset arrayAppend(borders,"Joe")/>
<cfset arrayAppend(borders,"Jamie")/>
<cfset arrayAppend(borders,"Jake")/>


<cfset borders = ""/>

<cfset borders = listAppend(borders,"Joe")/>
<cfset borders = listAppend(borders,"Jamie")/>
<cfset borders = listAppend(borders,"Jake")/>


I used both ways a ton this week and kept wanting to call listAppend() the same way arrayAppend() is called...but sadly listAppend() doesn't work like that. For some weird reason you need to set boarders (the list var) back to itself because listAppend() doesn't just add it to the variable above just like arrayAppend() does. listAppend() returns you the list with the new append value. Why? I just want to use it like arrayAppend()...it's cleaner and smaller code. Maybe I am missing an important point of listAppend() or don't understand a concept fully, but this is bugging me.

No comments:

Post a Comment