arraySome

Calls a given closure/function with every element in a given array and returns true if one of the closure calls returns true

arraySome(array, function(item [,index, array]){} [, parallel] [, maxThreads]) → returns boolean

Member Function Syntax

someArray.some(function(item [,index, array]){} [, parallel] [, maxThreads])

Argument Reference

array array
Required

Array to iterate

callback boolean
Required

Closure or a function reference that will be called for each of the iteration.

Callback parameters:

  • value*any : The value for the current iteration
  • index*numeric : The current index for the iteration
  • array*array : A reference of the original array

parallel boolean

Lucee 4.5+ Execute closures parallel

maxThreads numeric
Default: 20

Lucee 4.5+ Maximum number of threads executed, ignored when argument "parallel" is set to false

Links more information about arraySome

Examples
Sample code invoking the arraySome function

// Create an array
arrayList = ["apple", "pineapple", "mango", "apricot"];

// Match some
result = arraySome(arrayList, function(fruit) {
    return fruit.startsWith("a");
});

// Print result
writeOutput((result ? "Some" : "No") & " matches  were found!");

Expected Result: Some matches were found!

// Create an array
arrayList = ["apple", "pineapple", "mango", "apricot"];

// Match some
result = arrayList.some(function(fruit) {
    return fruit.endsWith("a");
});

// Print result
writeOutput((result ? "Some" : "No") & " matches  were found!");

Expected Result: No matches were found!

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub