– Common Function Library Project

arrayCompact(arr[, delim])

Last updated March 2, 2007


M Gillespie for HOUCFUG

Version: 1 | Requires: CF6 | Library: DataManipulationLib

This function is designed to remove undefined postions from an array. Will not work in CF5, and would not recommend using it for large arrays. Optional argument to pass in delimiter (default is Pipe symbol).

Return Values:
Returns an array.


<!--- create the array --->
<cfset tmp=arraynew(1)>
<cfset tmp[1]="a">
<cfset tmp[3]="c">
<cfset tmp[4]="d">
<!--- let's see it in all it's un-glory --->
<cfdump var="#tmp#" label="original array">
<!--- compacting - grindgrindgrind --->
<cfset newTmp=arrayCompact(tmp)>
<!--- show me --->
<cfdump var="#Newtmp#" label="New Compacted array">
<!--- now, the pudding --->
Looping new Array<br />
<cfloop from="1" to="#arraylen(newTmp)#" index="i">
index #i# = #newTmp[i]#<br />


Name Description Required
arr Array to compact. Yes
delim Temporary list delimiter. Defaults to |. No

Full UDF Source:

 * Used to remove missing positions from an array.
 * @param arr 	 Array to compact. (Required)
 * @param delim 	 Temporary list delimiter. Defaults to |. (Optional)
 * @return Returns an array. 
 * @author M Gillespie for HOUCFUG ( 
 * @version 1, March 2, 2007 
function arrayCompact(arr) {
	var delim="|";
	if(arraylen(arguments) gt 1) {delim=arguments[2];}
	return listtoarray(arraytolist(arr,delim),delim);
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson