Select to view content in your preferred language

Returning Specific Portions of an Arcade Split Function

1882
2
07-27-2020 06:06 AM
DaveK
by
Frequent Contributor

Hello! 

I am trying to split data using the Split function and pull out specific portions of the array. Once my data is split and I try to pull out a specific section, I receive an error stating "Execution Error:Runtime Error: Out of Bounds." 

The code below works and pulls out the first section of data. 

var txt = $feature["C1_BASIS"];
var arr = Split(txt, ";");
return arr[0]

However this block of code returns the out of bounds error when I try and pull out the next section of data. 

var txt = $feature["C1_BASIS"];
var arr = Split(txt, ";");
return arr[1]

How can I return the individual sections of my split? 

Thanks! 

Tags (2)
0 Kudos
2 Replies
Egge-Jan_Pollé
MVP Regular Contributor

Hi David Krady‌,

What is the length of your array, i.e. how may items does your array contain?

Some investigation:

  • You can use the function Count() to get the number of items in an array
  • You get the full array with return arr, just to verify the content

If there is no second item in your array, then the error message is correct.

I wrote a small script to test:

var txt = "person1;person2;person3";
var arr = Split(txt, ";");
//return Count(arr)
return arr // expected output [ person1 , person2 , person3 ] 
//return arr[0] // expected output person1
//return arr[1] // expected output person2
//return arr[2] // expected output person3
//return arr[3] // expected output Execution Error:Runtime Error: Out of Bounds. 

HTH,

Egge-Jan

0 Kudos
DaveK
by
Frequent Contributor

Egge-Jan Pollé

Each record contains a different number of items. some records contain a single item and another may contain 5. For example in the image below, the first record contains a single item and the second contains 6 items separated by semicolons. When I use the count function it only returns 1 item in the array because it seems to be looking at a record with only 1 item. 

Thanks. 

0 Kudos