Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListAppend() not working?

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.

like image 721
Mohsin Avatar asked Jun 26 '12 16:06

Mohsin


People also ask

How do I append a list to a different list?

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.

Can you append a 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).


2 Answers

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") />
like image 116
Scott Stroz Avatar answered Oct 18 '22 03:10

Scott Stroz


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.

like image 29
Greg Avatar answered Oct 18 '22 05:10

Greg