# "if"-Statement based on variables within an array

**URL:** <https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112>\
**Category:** Support, Troubleshooting, & Help\
**Created:** [October 30, 2019, 3:21pm UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112 "2019-10-30T15:21:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sathya](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/sathya/32/19_2.png) [@Sathya](https://community.tulip.co/u/Sathya)\
**Post date:** [October 30, 2019, 3:21pm UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/1 "2019-10-30T15:21:59Z")

</div>

I am currently working on an app and I was wondering how (or even if) I can make an “if”-Statement based on variables within an array, without first having to transfer the index to a separate variable.

---

<div class="post-metadata">

**Author:** ![Wei](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/wei/32/25_2.png) [@Wei](https://community.tulip.co/u/Wei)\
**Post date:** [October 30, 2019, 3:38pm UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/2 "2019-10-30T15:38:34Z")

</div>

Yes, you can use the “ARRAYCONTAINS()” function in the Expression Editor to see if an array contains the value of a specific variable. Let’s imagine that you have an array of text values, and you want to see if one of them contains the value in a text variable.

Here is how you would accomplish that in an “If” statement:

![](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/1X/a55bf76749df41d94132efb30a7790196f27bed5.png)

---

<div class="post-metadata">

**Author:** ![ermingut](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermingut](https://community.tulip.co/u/ermingut)\
**Post date:** [March 25, 2021, 4:38pm UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/3 "2021-03-25T16:38:31Z")

</div>

Hi.

I would like ti use above functionality to check if value is already in array. If it is then, message will be shown (Already in array - or something similar) otherwise I will add value to string array.

But unfortunately i cant save expression. At save gives mi an error "Type boolean is not valid in this context.

Bellow are some screenshots what was tried:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/7/7a319454b487ea1928873ac64efc3a52735022a9.png)

Expression seems to be OK. But at save I get above message.

![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/e/edab791b5f96a556a554f0d8484ef4700a3df18b.png)

Same happens if I replace variables with fixed array.

Thank you for help.  
Ermin

---

<div class="post-metadata">

**Author:** ![gio](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/gio/32/82_2.png) [@gio](https://community.tulip.co/u/gio)\
**Post date:** [March 25, 2021, 7:35pm UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/4 "2021-03-25T19:35:39Z")

</div>

hello @ermingut, thanks for sharing!! we can certainly help out here.

can you confirm that the Variable `arraySelectedParents` is indeed type Array of type Text??

this is the behavior I’m getting on my test App with a Text Array. Trigger:

 ![Screen Shot](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/f/fb47030119ce686d5b469ef97329a6079e161f60.jpeg)  
App:  
 ![Screen Shot 1](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/1/109164daa2defb46bad4aed84ce0ff35f97623c7.jpeg)

if you could share a screenshot of the App Variables we can help out here.

---

<div class="post-metadata">

**Author:** ![ermingut](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermingut](https://community.tulip.co/u/ermingut)\
**Post date:** [March 26, 2021, 6:23am UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/5 "2021-03-26T06:23:14Z")

</div>

Hi.

Yesterday I tried also with fixed array like ARRAYCONTAINS([‘1’,‘2’,‘3’], ‘1’) and got same error. I tried again just now and code is accepted. Below you can see that variable arraySelectedParents is indeed array.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/1/162e4769c0cb073563ee4245997a812667b4327e.png)

Interesting.

Thank you,  
Ermin

---

<div class="post-metadata">

**Author:** ![gio](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/gio/32/82_2.png) [@gio](https://community.tulip.co/u/gio)\
**Post date:** [March 26, 2021, 8:55am UTC](https://community.tulip.co/t/if-statement-based-on-variables-within-an-array/112/6 "2021-03-26T08:55:17Z")

</div>

hello @ermingut, thanks for the update!!

I’m not sure as to why it wasn’t working yesterday, let us know if it happens again.
