– Common Function Library Project

isArrayOf(object, validator)

Last updated December 19, 2012


Adam Cameron

Version: 1 | Requires: CF9 | Library: CFMLLib

Validates an array of [anything] using a callback to define what constitutes a valid [anything]. The callback should return a boolean: true if the passed-in array element is valid, otherwise false.

Return Values:
Returns a boolean


numbers = [
    {number=1, english="one", maori="tahi"},
    {number=2, english="two", maori="rua"},
    {number=3, english="three", maori="toru"},
    {number=4, english="four", maori="wha"}

function numbersValdiator(number){
    return structKeyExists(number, "number") && structKeyExists(number, "english") && structKeyExists(number, "maori");

writeOutput(isArrayOf(numbers, numbersValdiator));


Name Description Required
object The object to validate Yes
validator The callback to use to validate each element in the array Yes

Full UDF Source:

 * Validates an array of [anything].
 * version 1.0 by Adam Cameron
 * @param object 	 The object to validate (Required)
 * @param validator 	 The callback to use to validate each element in the array (Required)
 * @return Returns a boolean 
 * @author Adam Cameron ( 
 * @version 1.0, December 19, 2012 
function isArrayOf(object, validator){
    if (!isArray(object)){
        return false;

    for (var element in object){
        if (!validator(element)){
            return false;
    return true;
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