Parameter
Zuletzt aktualisiert am
30. April 2021
Description
Determines if all elements of an array satisfy a given condition.
Returns
True if all elements match a condition; false, otherwise.
Syntax
ArrayEvery(array, callback)
Member function
arrayObj.Every(callback)
History
New in ColdFusion (2018 release) Update 5: Added the function.
Parameters
|
Required/Optional |
Description |
---|---|---|
array |
Required |
Array in which all elements are to be searched. |
callback |
Required |
Function that encapsulates criteria . |
Example
Example 1
<cfscript> array1=[1,2,3,4,5] isEven=(x)=>return x%2==0 writeOutput(arrayEvery(array1,isEven)) // Returns False </cfscript>
Example 2
<cfscript> arrayAllEven=[2,4,6,8,10,12,14] isEven=(x)=>return x%2==0 writeOutput(arrayEvery(arrayAllEven,isEven)) // Returns True </cfscript>
Example 3
<cfscript> myarray=[2,4,6,8,10,12,14] isGT10=(element,index,array)=>return element>10 writeoutput(arrayEvery(myarray,isGT10)) // Returns True writeoutput(myarray.Every(isGT10)) // Returns False </cfscript>
Exampe 4 - Using named parameters
<cfscript> myarray=[2,5,8,1,4] callback=function(element,index,array){ return element<10 } result=ArrayEvery(array=myarray,callback=callback) writeOutput(result) // Returns True </cfscript>
Example 5 - Using arrow function
<cfscript> myarray=[2,5,8,1,4,12,29] callback=(element,index,array)=>{ return element>10 } result=ArrayEvery(array=myarray,callback=callback) writeOutput(result) // Returns False </cfscript>
Member function
<cfscript> array1=[1,2,3,4,5] isEven=(x)=>return x%2==0 writeOutput(array1.Every(isEven)) </cfscript>