How to write a condition for element which is not present in an array

187 views Asked by At

I want this code to be executed if the array s does not contain the element in curr variable. How do I need to modify the if condition?

<cfif s.contains(#curr#)>
    <cfset ArrayAppend(s,curr)>
    <cfset en++>
    <cfset cl=en-st>
</cfif>
1

There are 1 answers

0
Dan Bracuk On

The function you want is ArrayFind. Documentation is here ==> https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-a-b/arrayfind.html

You want something like this:

<cfif ArrayFind(s, curr) is 0>
    <cfset ArrayAppend(s,curr)>
    <cfset en++>
    <cfset cl=en-st>
</cfif>