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
Post a Comment