CFLib.org – Common Function Library Project

ArrayDefinedAt(arr, pos)

Last updated October 24, 2003

Version: 2 | Requires: ColdFusion MX | Library: DataManipulationLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
Returns true if a specified array position is defined.

Return Values:
Returns a boolean.

Example:

view plain print about
<cfscript>
a = arrayNew(1);
a[1] = "d";
a[2] = "e";
a[4] = "f";
for(i = 1; i lte arrayLen(a); i=i+1) {
    if(arrayDefinedAt(a,i)) writeOutput("a#i# is #a[i]#<br>");
    else writeOutput("a#i# is undefined<br>");
}
</cfscript>

Parameters:

Name Description Required
arr The array to check. Yes
pos The position to check. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Returns true if a specified array position is defined.
 * 
 * @param arr      The array to check. (Required)
 * @param pos      The position to check. (Required)
 * @return Returns a boolean. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 2, October 24, 2003 
 */

function arrayDefinedAt(arr,pos) {
    var temp = "";
    try {
        temp = arr[pos];
        return true;
    } 
    catch(coldfusion.runtime.UndefinedElementException ex) {
        return false;
    }
    catch(coldfusion.runtime.CfJspPage$ArrayBoundException ex) {
        return false;
    }
}
</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