Arcade syntax question: checking if value is in a list

411
2
Jump to solution
08-17-2020 06:57 AM
Katherine_Clark
MVP Regular Contributor

Hello,

I am hoping this is a fairly simple question but I'm just a bit unclear on the syntax for Arcade and haven't been able to find the answer I need.

I want to return a certain value based on whether the county name is in a predefined list or not.

Something like this:

var counties = ['County1', 'County2']
if ( $feature.NAME IN counties ) {
return "Processed"
}
else {
return "Not Processed"
}

Thanks in advance for any guidance!

Cheers,

KC

0 Kudos
1 Solution

Accepted Solutions
JoshuaSharp-Heward
Occasional Contributor

Not sure if this is the offical way of doing this but if you use indexOf(list, value) and the value isn't in the list it returns a -1, so you can set up a little switch using it! See below:

var counties = ['County1', 'County2']

IIF(indexOf(counties, $feature.NAME) != -1, "Processed", "Not Processed")‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
JoshuaSharp-Heward
Occasional Contributor

Not sure if this is the offical way of doing this but if you use indexOf(list, value) and the value isn't in the list it returns a -1, so you can set up a little switch using it! See below:

var counties = ['County1', 'County2']

IIF(indexOf(counties, $feature.NAME) != -1, "Processed", "Not Processed")‍‍‍‍‍‍‍‍‍‍‍‍
Katherine_Clark
MVP Regular Contributor

Thanks for the quick reply! That works!