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, callback)

Member function

arrayObj.Some(callback)

History

New in ColdFusion (2018 release) Update 5: Added the function.

Parameters

Parameter

Required/Optional

Description

array

Required

Array in which at least one element is to be searched.

callback

Required

Function to encapsulate the criteria.

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>