I have a function that receives a string of tags. In order to save the tags individually, the function transforms the string into an array:
this.tags = listToArray(this.tags, ", ");
How do I remove duplicate values in the event that there are any?
An easy way to remove duplicates from a list is to convert the list to a struct first, and then conver the struct to an array. However if the order of items in the list is important this may not be appropriate as the elements in the struct will be sorted.
If the order of items is important you would need to build the array manually rather than using the listToArray feature.
<!--- CF9 --->
<cfset tags = "apples,oranges,bananas,pears,APPLES" />
<cfset tagArray = arrayNew(1) />
<cfloop list="#tags#" index="tag" delimiters=",">
<cfif not ArrayFindNoCase(tagArray,tag)>
<cfset arrayAppend(tagArray, tag) />
</cfif>
</cfloop>