# How to do this in no code? Find if an array contains another array

**URL:** <https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961>\
**Category:** How do I?\
**Created:** [December 15, 2023, 9:07am UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961 "2023-12-15T09:07:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![raelyn](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raelyn/32/2803_2.png) [@raelyn](https://community.weweb.io/u/raelyn)\
**Post date:** [December 15, 2023, 9:07am UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/1 "2023-12-15T09:07:37Z")

</div>

I have an array of values (let’s call it array 1). I have another array of values (array 2).

Example:

Array 1: [1,2,3,4,5]  
Array 2: [1,4,5]

How do I check if array 1 contains all the values of array 2 to return true or false, using no code?

In this case it will return true as Array 1 contains all values of Array 2.

I was thinking use the “Contains” filter but that only applies if Array 2 is a single value and not a list.

---

<div class="post-metadata">

**Author:** ![Mark\_Pederson](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mark_pederson/32/14758_2.png) [@Mark\_Pederson](https://community.weweb.io/u/Mark_Pederson)\
**Post date:** [December 15, 2023, 12:22pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/2 "2023-12-15T12:22:40Z")

</div>

I would create a boolean variable - “doesContain” set to false

Then do a for each loop on array 1

If Array 2 does NOT contain (“contains” filter using item from loop) then RETURN w response of doesContain (breaks out and ends loop)

loop completes if Array 2 DOES contain - after the loop is complete you change variable doesContain to True - and return that as a response.

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [December 15, 2023, 6:39pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/3 "2023-12-15T18:39:23Z")

</div>

I’d say you could make this into a formula yourself.

```auto
return subArray.every(element => mainArray.includes(element))

```

and set parameters mainArray and subArray in your formula configuration like such

 ![Screenshot 2023-12-15 at 19.45.15](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/8/8e2063fa799020e8e399064174dae8a2b98ff905.png)

I’m wondering there is not a no-code formula for this.

---

<div class="post-metadata">

**Author:** ![Mark\_Pederson](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mark_pederson/32/14758_2.png) [@Mark\_Pederson](https://community.weweb.io/u/Mark_Pederson)\
**Post date:** [December 15, 2023, 7:21pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/4 "2023-12-15T19:21:05Z")

</div>

Love this.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [December 15, 2023, 7:30pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/5 "2023-12-15T19:30:13Z")

</div>

Also a nice article about simple useful array manipulation that can be included as formulas: [Array intersection, difference, and union in ES6 | by Alvaro Saburido | Medium](https://medium.com/@alvaro.saburido/set-theory-for-arrays-in-es6-eb2f20a61848)

---

<div class="post-metadata">

**Author:** ![raelyn](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raelyn/32/2803_2.png) [@raelyn](https://community.weweb.io/u/raelyn)\
**Post date:** [December 16, 2023, 9:06am UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/6 "2023-12-16T09:06:54Z")

</div>

> [@Broberto](#):
>
> ```auto
> return subArray.every(element => mainArray.includes(element))
> 
> ```

Hey Broberto! So I have created the formula exactly like you suggested in the “Formulas” section:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/bdaa11621ccedda3a19d786a36911a9fa61271cc.png)

Now outside of the Formulas section in my app, I want to see if array 1 contains array 2 how do I do it?

For example, I have this text that I want to display if the subArray is within the mainArray:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/bf01b95d0e81ec374a9c090488e395338997d18d.png)

I added the formula but don’t see a way to tell the formula what’s my mainArray and what’s my subArray?

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [December 16, 2023, 9:14am UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/7 "2023-12-16T09:14:15Z")

</div>

First of all, you’re not switching the Parameter type to Array, you’re using Text instead. I had the exact same issue haha.

When you hover on the formula, it should show you the order. You basically just need to pass the parameters in order, as you would in any other formula in your case, you would first pass the array that IS CONTAINED and secondly pass the array that CONTAINS IT

sorry for the caps, but bold seems to not work on the forum for some reason. @Joyce is there any specific reason why markup doesn’t seem to work?

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [December 18, 2023, 3:55pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/8 "2023-12-18T15:55:29Z")

</div>

> [@Broberto](#):
>
> sorry for the caps, but bold seems to not work on the forum for some reason. @Joyce is there any specific reason why markup doesn’t seem to work?

No idea. It seems to be a Discourse bug. Bold used to work but doesn’t anymore

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [December 18, 2023, 3:56pm UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/9 "2023-12-18T15:56:37Z")

</div>

Hi @raelyn 👋

Not sure if you caught this but in your first screenshot you wrote the `return` statement twice so your formula won’t work

---

<div class="post-metadata">

**Author:** ![raelyn](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raelyn/32/2803_2.png) [@raelyn](https://community.weweb.io/u/raelyn)\
**Post date:** [December 21, 2023, 2:29am UTC](https://community.weweb.io/t/how-to-do-this-in-no-code-find-if-an-array-contains-another-array/5961/10 "2023-12-21T02:29:57Z")

</div>

Oh!! Right 😁
