how to check if elements of one list exist in another list in coldfusion

 if there are 2 lists, and if we need to check elements of one list exists in another list. Then you can use the following code :


<cfset list1 = "Red,Blue,Green,Yellow">

<cfset list2 = "Blue,White,Black">


<cfset isfound = false>

<cfloop list="#list1#" index="item">

    <cfif ListFind(list2, item)>

        <cfset isfound = true>

        <cfbreak>

    </cfif>

</cfloop>


<cfif isfound >

    <cfoutput>At least one item from list1 exists in list2</cfoutput>

<cfelse>

    <cfoutput>No items from list1 found in list2</cfoutput>

</cfif>

Comments

Popular posts from this blog

how to add new line in google form questions | Fix for next line issue in google form questions

How to add new line in the 'add title and description' section in google forms