Easiest way to check if list contains item

Hey friends,

Im trying to check if a list contains any of these values. The way im setting this up right now is like this:

List.contains(“Number”)or List.contains(“Department”) or List.contains(“Ready”)

But I feel like there should be an easier method because I have to check for many values. So something like
List.contains(“Number”, “Department”, “Ready”)

Is this possible? And if so how can I do this.

@Peter_Peter
have a look on this as it could help to start

@Peter_Peter

Your Search list is {“Number”, “Department”, “Ready”}

YourSearchList.All(function(x) MainList.Contains(x)).ToString

the above code will return true only if all you Search list value match otherwise it returns false

2 Likes

To check whether the list contains all the required items.

Steps:

  1. “listVar1” is the list that you want to check for multiple items.
  2. “listVar2” contains the items whose existense is to be checked in “listVar1.”
  3. Use method in If condition -

listVar1.Except(listVar2).ToList.Count.Equals(listVar1.Count - listVar2.Count)

Explanation -

  1. listVar1.Except(listVar2).ToList : gives all the items from listVar1 that are not in listVar2.
  2. listVar1.Except(listVar2).ToList.Count : gives number of the items from listVar1 that are not in listVar2.
  3. listVar1.Count - listVar2.Count : gives the difference between number of items in listVar1 and listVar2

If list1 contains all the items from listVar2, then the result of Explanation point 2 and Explanation point 3 will match, and output of the above query will be True, else False.