Parameter
You can also set the maximum thread count in ColdFusion Administrator. Click Server Settings > Settings and specify the number of threads in Default Maximum Thread Count For Parallel Functions.
Description
Determines if at least one element in the array satisfies a given condition.
Returns
True if at least one element matches a condition; false, otherwise.
Syntax
arraySome(array, function(item [,index, array]){} [, parallel] [, maxThreadCount])
Member function
arrayObj.Some(callback)
History
ColdFusion (2021 release): Introduced the following parameters:
- parallel
- maxThreadCount
ColdFusion (2018 release) Update 5: Added the function.
Parameters
|
Required/Optional |
Description |
---|---|---|
array |
Required |
Array in which at least one element is to be searched. |
callback |
Required |
Function to encapsulate the criteria. |
parallel |
Optional |
True if you want to enable parallel programming. |
maxThreadCount |
Optional |
The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
Example
Example 1
<cfscript> array1=[1,2,3,4,5] isEven=(x)=>return x%2==0 writeOutput(arraySome(array1,isEven)) // Returns TRUE </cfscript>
Example 2
<cfscript> myarray=[2,4,6,8,10,12,14] isGT10=(element,index,array)=>return element>10 writeoutput(arraySome(myarray,isGT10)) // Returns True // Using member function writeoutput(myarray.Some(isGT10)) // Returns True </cfscript>
Example 3 - Using named parameters
<cfscript> myarray=[2,5,8,1,4] callback=function(element,index,array){ return element>10 } result=ArraySome(array=myarray,callback=callback) writeOutput(result) // Returns False </cfscript>
Example 4 - Using arrow function
<cfscript> myarray=[2,5,8,1,4] callback=(element,index,array)=>{ return element<10 } result=ArraySome(array=myarray,callback=callback) writeOutput(result) // Returns True </cfscript>
Member function
<cfscript> array1=[1,2,3,4,5] isEven=(x)=>return x%2==0 writeOutput(array1.Some(isEven)) </cfscript>
Using parallelization
<cfscript> for(i=1;i<=10000;i++){ if(i == 4500){ arr[i]=0; } else arr[i]=i*2; } result = arr.some(function(item){ if (item Mod 2 == 0) return false return true },true,20) writeoutput(result) </cfscript>