arrayFindAll

Searches an array for all positions of a specified object. The function searches for simple objects such as strings and numbers or for complex objects such as structures. When the second parameter is a simple object, string searches are case-sensitive

arrayFindAll(array, object or closure) → returns array

Member Function Syntax

someArray.findAll(object or closure)

arrayFindAll Argument Reference

array array
Required

The source array to search through

object or closure variableName
Required

If string, case sensitive value to search for; if closure, use signature function (item, index, array) : boolean

Examples sample code invoking the arrayFindAll function


List all courses with participants

courses = [{
    name: "Getting started with ColdFusion",
    participants: []
},{
    name: "Caching in ColdFusion",
    participants: [{
        name: "John Doe",
        age: 45
    },{
        name: "Jane Doe",
        age: 46
    }]
},{
    name: "Changeover to Lucee",
    participants: []
},{
    name: "Update ColdFusion",
    participants: [{
        name: "Arthur Dent",
        age: 42
    }]
}];

choosenCourses = arrayFindAll(courses,function(course) {
    return arrayLen(course.participants);
});

writeOutput(ArrayToList(choosenCourses));

Expected Result: 2,4


Fork me on GitHub