CF Method to Merge a List and Array

Here’s a little method I wrote to merge a CF list into an existing array.

	/**
	* mergeListToArray
	* When provided a list and an array, we convert the list to an array and merge them.
	* @created	11/07/2011
	* @author	Ryan Mueller
	* @param	{Array}		a		Array to merge list to		{required}
	* @param	{String}	l		List to merge with array	{required}
	* @param	{String}	delim	Delimiters to use	default = ','
	* @return	{Array}
	*/
	public Array function mergeListToArray(required array a,required string l,required string delim=','){
		var tmpArr = ListToArray(trim(arguments.l),delim);
		var newArr = arguments.a;
		if(IsArray(newArr) && IsArray(tmpArr)){
			// loop over current array and append to new array
			for(i=1; i LTE ArrayLen(tmpArr); i=(i+1)){
				ArrayAppend(newArr,tmpArr[i]);
			}//end loop
		}//end isarray
		return newArr;
	};

 

Leave a Reply

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