Create an array out of a string using Arcade?

1781
2
Jump to solution
08-10-2020 01:50 PM
TL2
by
Occasional Contributor III

When I hard code in an array...

var array = ["2", "2"]

... right into the expression, it works.  

However, when I add that same array into a field, then call that field instead within the function, it doesn't see it as an array.  

$feature.array = ["2", "2"]‍‍

var array = $feature.array

Is there a way to call a string from a field and have the expression read it as a array?

Xander Bakker

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi T L ,

When you have a feature with a field called array (probably a text field) and you edit the field to type in ["2", "2"], it will not be an array. As Joshua Bixby asked, if you would put the text "2,2" (without the quotes) in a field, you could use the Split function to split the text up and create the array: 

When you click on a "2" in the result, you will see that each element is in fact a string:

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

What does the string from the field look like? Is it something like "2, 2"?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi T L ,

When you have a feature with a field called array (probably a text field) and you edit the field to type in ["2", "2"], it will not be an array. As Joshua Bixby asked, if you would put the text "2,2" (without the quotes) in a field, you could use the Split function to split the text up and create the array: 

When you click on a "2" in the result, you will see that each element is in fact a string: