This is an arcade-specific question about using arrays.
I am building a popup based off of this previous post: https://community.esri.com/t5/arcgis-online-documents/hide-field-in-pop-up-using-arcade/ta-p/1029496 and would like to create a 'master list' of field names that always apply to a popup while adding in additional fields based on the content of a specific field.
So, say I have an array of ['a', 'b','c'] and a second array of ['h','j', '5'].
How can I merge those two arrays together into ['a', 'b','c', 'h','j', '5'] (or any other combination of fields, the arrangement doesn't matter currently)?
This is easy enough to do with Python, but I can't find a simple way to do this with Arcade. I was trying to use Insert but when I did the below code segment, I only got the indexes of the array values instead of the values themselves.
var lst1 = ['a', 'b','c'];
var lst2 = ['h','j', '5'];
var newlst = [];
for ( var i in lst2) {
Insert(lst1, 0, i)
}
return lst1
Solved! Go to Solution.
The only thing wrong with your code is that you have to remember when looping through an array, the variable represents the index of the item in the array, not the value of the item itself.
This work properly
var lst1 = ['a', 'b','c'];
var lst2 = ['h','j', '5'];
var newlst = [];
for ( var i in lst2) {
Insert(lst1, 0, lst2[i]);
}
return lst1;
@RVx_GaslineGiS If you want just to join two arrays in arcade, you can check XanderBakker's answer in following link https://community.esri.com/t5/arcgis-pro-questions/lists-in-arcade/td-p/326336 At least first one seems to work fine.
The only thing wrong with your code is that you have to remember when looping through an array, the variable represents the index of the item in the array, not the value of the item itself.
This work properly
var lst1 = ['a', 'b','c'];
var lst2 = ['h','j', '5'];
var newlst = [];
for ( var i in lst2) {
Insert(lst1, 0, lst2[i]);
}
return lst1;
Thank you, that was the simple thing I was missing.