arraySlice(ary [, start] [, finish])
Last updated July 13, 2005
Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib
Description:
Returns a slice of an array.
Return Values:
Returns an array.
Example:
a = arrayNew(1);
a[1] = "this";
a[2] = "is";
a[3] = "the";
a[4] = "best";
a[5] = "udf";
a[6] = "that";
a[7] = "has";
a[8] = "ever";
a[9] = "been";
a[10] = "written";
</cfscript>
<cfdump var="#a#">
<cfdump var="#arrayslice(a, 2, 3)#">
<cfdump var="#arrayslice(a, 7)#">
<cfdump var="#arrayslice(a)#">
Parameters:
| Name | Description | Required |
|---|---|---|
| ary | The array to slice. | Yes |
| start | The index to start with. Defaults to 1. | No |
| finish | The index to end with. Defaults to the end of the array. | No |
Full UDF Source:
<cfscript>
/**
* Slices an array.
*
* @param ary The array to slice. (Required)
* @param start The index to start with. Defaults to 1. (Optional)
* @param finish The index to end with. Defaults to the end of the array. (Optional)
* @return Returns an array.
* @author Darrell Maples (drmaples@gmail.com)
* @version 1, July 13, 2005
*/
function arraySlice(ary) {
var start = 1;
var finish = arrayLen(ary);
var slice = arrayNew(1);
var j = 1;
if (len(arguments[2])) { start = arguments[2]; };
if (len(arguments[3])) { finish = arguments[3]; };
for (j=start; j LTE finish; j=j+1) {
arrayAppend(slice, ary[j]);
}
return slice;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)