I have a problem with my cfml code. The ListAppend()
function doesn't seem to be working.
Here is the code in my .cfm page:
<cfset fruitList="apple, orange, banana">
<cfoutput>
fruitList before: #fruitList#<br>
</cfoutput>
<cfset temp = ListAppend(fruitList, "kiwi")>
<cfoutput>
fruitList after: #fruitList#<br>
</cfoutput>
But I always get this output:
fruitList before: apple, orange, banana
fruitList after: apple, orange, banana
The same goes for ListPrepend()
and ListInsertAt()
. Why does this happen?
Any help is appreciated.
To append a list to another list, use extend() function on the list you want to extend and pass the other list as argument to extend() function. In this tutorial, we shall learn the syntax of extend() function and how to use this function to append a list to other list.
append() adds a list inside of a list. Lists are objects, and when you use . append() to add another list into a list, the new items will be added as a single object (item).
listAppend() returns the new list (lists are nothing but strings, which ColdFusion passes by value) so in order for you to see appended value, you would need to use:
<cfset fruitlist = ListAppend(fruitList, "kiwi") />
Try
<cfset fruitList="apple, orange, banana">
<cfoutput>
fruitList before: #fruitList#<br>
</cfoutput>
<cfset fruitList=ListAppend(fruitList, "kiwi")>
<cfoutput>
fruitList after: #fruitList#<br>
</cfoutput>
Accord to cfquickdocs listAppend returns the list with the value appended to it. http://cfquickdocs.com/#ListAppend
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With