Select to view content in your preferred language

Does Arcade support multi-dimentional arrays?

222
2
Jump to solution
04-03-2024 11:19 AM
SteveCole
Frequent Contributor

I have some pop up logic written in for the Javascript API but I want to port that over to AGOL/Portal Web Map popups but my content logic revolves around the use of multi-dimensional arrays. I don't see anything explicitly stated in the documentation hence this post.

 

The context for this is that I have a census data layer which has 150 attribute fields with count values. For each non-zero value, it is added to a multi-dimensional array where the 1st column is a label, the second is the percentage based on a total population subset, and the third column in the array is the percentage based on the entire population of the census tract.

Once the array is fully populated, I sort the array in descending value order based on the 2nd column of the array and then build out an HTML table for the pop up. Anyways, I can do this in the JS API because it's pure JS but I'm not sure about Arcade.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
SteveCole
Frequent Contributor

In answer to my own question, the answer appears to be yes, they are supported. A simple test case:

arcade_2d_array_ex.jpg

Not sure about sorting it but I guess that's the next thing to tackle..

View solution in original post

0 Kudos
2 Replies
SteveCole
Frequent Contributor

In answer to my own question, the answer appears to be yes, they are supported. A simple test case:

arcade_2d_array_ex.jpg

Not sure about sorting it but I guess that's the next thing to tackle..

0 Kudos
SteveCole
Frequent Contributor

To follow up myself once again, you can sort the multi-dimensional array inside Arcade as well. The sort function below will sort in ascending order:

var a = [];
push(a,['Bahamas',22.5,5.78]);
push(a,['Cuba',10.2,2.9]);
push(a,['Argentina',4.6,1.1]);

function SortDesc(a,b){
  if (a[1]<b[1])
    return -1;
  if (a[1]>b[1])
    return 1;
  return 0;
}

var aSort = Sort(a,SortDesc);

Console(a[0]);
Console('The first column is: ' + a[0][0]);
Console('The second column is: ' + a[0][1]);
Console('The third column is: ' + a[0][2]);

Console(aSort[0]);
Console(aSort[1]);
Console(aSort[2]);

for(var index in aSort){
  Console(aSort[index][0]);
}

 

If you want descending order like I did, you simply reverse the order of the returned value in the function like this:

function SortDesc(a,b){
  if (a[1]<b[1])
    return 1;
  if (a[1]>b[1])
    return -1;
  return 0;
}

 

Although you reference array[][] using the double brackets in most parts of the code, the function only needs one set of brackets for the column. Happy hackling!..

 

 

0 Kudos