CFLib.org – Common Function Library Project

ArrayDeleteAtList(a, l)

Last updated January 21, 2005

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 0 time(s). Average Rating: 0

Description:
Deletes elements from an array passing the list of positions. Similar to ArrayDeleteAt but the position value could be a list of positions.

Return Values:
Returns an array.

Example:

view plain print about
<cfset myArr=ArrayNew(1)>
<cfset myArr[1]="1st">
<cfset myArr[2]="2nd">
<cfset myArr[3]="3rd">
<cfset myArr[4]="4th">
<cfset myArr[5]="5th">
<cfdump var="#myArr#" label="Original array">
<cfset list='1,5'>
To delete: <br />
<cfoutput>#list#</cfoutput><br />
<cfdump var="#ArrayDeleteAtList(myArr,list)#" label="parsedArray">

Parameters:

Name Description Required
a The array to modify. Yes
l The list of indexes to remove. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Deletes an elements list from an array.
 * 
 * @param a      The array to modify. (Required)
 * @param l      The list of indexes to remove. (Required)
 * @return Returns an array. 
 * @author Giampaolo Bellavite (giampaolo@bellavite.com) 
 * @version 1, January 21, 2005 
 */

function ArrayDeleteAtList(a,l) {
    var i=1;
    l = listSort(l, "numeric""desc");
    for(i=1; i lte listLen(l); i=i+1) arrayDeleteAt(a, listGetAt(l,i));
    return a;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson